diff options
author | Björn Gustavsson <[email protected]> | 2012-12-22 06:48:01 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-01-22 19:20:13 +0100 |
commit | 34baa02a2c41cfbc8c0f53da93157ec28e0c9d96 (patch) | |
tree | d868c1dfa8ff78e22fe2f7d40f4e001d84cd97b9 /lib/asn1/src/asn1rtt_ber.erl | |
parent | 76ad80f52981449af3c79fdf5b298e4c8d817788 (diff) | |
download | otp-34baa02a2c41cfbc8c0f53da93157ec28e0c9d96.tar.gz otp-34baa02a2c41cfbc8c0f53da93157ec28e0c9d96.tar.bz2 otp-34baa02a2c41cfbc8c0f53da93157ec28e0c9d96.zip |
BER run-time: Refactor decoding of string data types
In the BER run-time code (asn1rtt_ber), there is a general function
for decoding a string:
decode_restricted_string(Tlv, Range, StringType, TagsIn)
But the StringType argument is not important. It is only used
internally in asn1rtt_ber to distinguish universal strings and BMP
strings from other strings. By slightly refactoring the string
decoding code, we can eliminate the StringType argument and a
subsequent run-time test on the string type. That will slightly reduce
code size, slightly increase speed, and eliminate Dialyzer warnings.
Diffstat (limited to 'lib/asn1/src/asn1rtt_ber.erl')
-rw-r--r-- | lib/asn1/src/asn1rtt_ber.erl | 49 |
1 files changed, 13 insertions, 36 deletions
diff --git a/lib/asn1/src/asn1rtt_ber.erl b/lib/asn1/src/asn1rtt_ber.erl index e086612818..3c6ab3e1c4 100644 --- a/lib/asn1/src/asn1rtt_ber.erl +++ b/lib/asn1/src/asn1rtt_ber.erl @@ -33,11 +33,11 @@ decode_named_bit_string/3, decode_compact_bit_string/3, decode_legacy_bit_string/3, - decode_octet_string/3, encode_null/2,decode_null/2, encode_relative_oid/2,decode_relative_oid/2, encode_object_identifier/2,decode_object_identifier/2, - encode_restricted_string/2,decode_restricted_string/4, + encode_restricted_string/2, + decode_restricted_string/2,decode_restricted_string/3, encode_universal_string/2,decode_universal_string/3, encode_UTF8_string/2,decode_UTF8_string/2, encode_BMP_string/2,decode_BMP_string/3, @@ -1107,15 +1107,6 @@ decode_bitstring_NNL([0|BitList],NamedNumberList,No,Result) -> decode_bitstring_NNL(BitList,NamedNumberList,No+1,Result). %%============================================================================ -%% decode octet string -%% (Buffer, Range, HasTag, TotalLen) -> {String, Remain, RemovedBytes} -%% -%% Octet string is decoded as a restricted string -%%============================================================================ -decode_octet_string(Buffer, Range, Tags) -> - decode_restricted_string(Buffer, Range, ?N_OCTET_STRING, Tags). - -%%============================================================================ %% Null value, ITU_T X.690 Chapter 8.8 %% %% encode NULL value @@ -1252,33 +1243,16 @@ encode_restricted_string(OctetList, TagIn) when is_list(OctetList) -> %% decode Numeric Printable Teletex Videotex Visible IA5 Graphic General strings %%============================================================================ -decode_restricted_string(Tlv, Range, StringType, TagsIn) -> +decode_restricted_string(Tlv, TagsIn) -> Bin = match_and_collect(Tlv, TagsIn), - Val = decode_restricted(Bin, StringType), - check_and_convert_restricted_string(Val, Range). - -decode_restricted(Bin, StringType) -> - case StringType of - ?N_UniversalString -> - mk_universal_string(binary_to_list(Bin)); - ?N_BMPString -> - mk_BMP_string(binary_to_list(Bin)); - _ -> - Bin - end. + binary_to_list(Bin). -check_and_convert_restricted_string(Val0, Range) -> - {Len,Val} = if is_binary(Val0) -> - {byte_size(Val0),binary_to_list(Val0)}; - is_list(Val0) -> - {length(Val0),Val0} - end, - check_restricted_string(Val, Len, Range). +decode_restricted_string(Tlv, Range, TagsIn) -> + Bin = match_and_collect(Tlv, TagsIn), + check_restricted_string(binary_to_list(Bin), byte_size(Bin), Range). check_restricted_string(Val, StrLen, Range) -> case Range of - [] -> % No length constraint - Val; {Lb,Ub} when StrLen >= Lb, Ub >= StrLen -> % variable length constraint Val; {{Lb,_Ub},[]} when StrLen >= Lb -> @@ -1324,8 +1298,9 @@ mk_uni_list([H|T],List) -> %%=========================================================================== decode_universal_string(Buffer, Range, Tags) -> - decode_restricted_string(Buffer, Range, ?N_UniversalString, Tags). - + Bin = match_and_collect(Buffer, Tags), + Val = mk_universal_string(binary_to_list(Bin)), + check_restricted_string(Val, length(Val), Range). mk_universal_string(In) -> mk_universal_string(In, []). @@ -1386,7 +1361,9 @@ mk_BMP_list([H|T], List) -> %% {String, Remain, RemovedBytes} %%============================================================================ decode_BMP_string(Buffer, Range, Tags) -> - decode_restricted_string(Buffer, Range, ?N_BMPString, Tags). + Bin = match_and_collect(Buffer, Tags), + Val = mk_BMP_string(binary_to_list(Bin)), + check_restricted_string(Val, length(Val), Range). mk_BMP_string(In) -> mk_BMP_string(In,[]). |