diff options
author | Björn Gustavsson <[email protected]> | 2012-12-21 15:08:59 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-01-22 19:20:13 +0100 |
commit | 2e57d4603575f492f54409e8235806ee6702944c (patch) | |
tree | a94fcbb5292e042aa5b0c15bca237da643022fd7 /lib | |
parent | 3f8be66021a5b3ce764181a2f9685ed7bfc81607 (diff) | |
download | otp-2e57d4603575f492f54409e8235806ee6702944c.tar.gz otp-2e57d4603575f492f54409e8235806ee6702944c.tar.bz2 otp-2e57d4603575f492f54409e8235806ee6702944c.zip |
uper: Look up some SizeConstraints at compile-time
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asn1/src/asn1ct_gen_per.erl | 12 | ||||
-rw-r--r-- | lib/asn1/src/asn1rtt_uper.erl | 31 |
2 files changed, 26 insertions, 17 deletions
diff --git a/lib/asn1/src/asn1ct_gen_per.erl b/lib/asn1/src/asn1ct_gen_per.erl index b7f3a12040..a43975a308 100644 --- a/lib/asn1/src/asn1ct_gen_per.erl +++ b/lib/asn1/src/asn1ct_gen_per.erl @@ -158,8 +158,9 @@ gen_encode_prim(Erules,D,DoTag,Value) when is_record(D,type) -> emit_enc_real(Erules, Value); {'BIT STRING',NamedNumberList} -> + SizeConstr = get_constraint(Constraint, 'SizeConstraint'), call(Erules, encode_bit_string, - [{asis,Constraint},Value, + [{asis,SizeConstr},Value, {asis,NamedNumberList}]); 'NULL' -> emit("[]"); @@ -173,7 +174,14 @@ gen_encode_prim(Erules,D,DoTag,Value) when is_record(D,type) -> 'BOOLEAN' -> call(Erules, encode_boolean, [Value]); 'OCTET STRING' -> - call(Erules, encode_octet_string, [{asis,Constraint},Value]); + case get_constraint(Constraint, 'SizeConstraint') of + 0 -> + emit("[]"); + no -> + call(Erules, encode_octet_string, [Value]); + C -> + call(Erules, encode_octet_string, [{asis,C},Value]) + end; 'NumericString' -> call(Erules, encode_NumericString, [{asis,Constraint},Value]); TString when TString == 'TeletexString'; diff --git a/lib/asn1/src/asn1rtt_uper.erl b/lib/asn1/src/asn1rtt_uper.erl index 34971f09e3..a9479471eb 100644 --- a/lib/asn1/src/asn1rtt_uper.erl +++ b/lib/asn1/src/asn1rtt_uper.erl @@ -27,7 +27,7 @@ encode_boolean/1, encode_length/1, encode_length/2, encode_bit_string/3]). --export([encode_octet_string/2, +-export([encode_octet_string/1,encode_octet_string/2, encode_relative_oid/1, decode_relative_oid/1, encode_object_identifier/1, decode_object_identifier/1, complete/1, complete_NFP/1]). @@ -496,10 +496,10 @@ encode_boolean(Val) -> encode_bit_string(C, {Unused,BinBits}=Bin, NamedBitList) when is_integer(Unused), is_binary(BinBits) -> - encode_bin_bit_string(get_constraint(C,'SizeConstraint'),Bin,NamedBitList); + encode_bin_bit_string(C, Bin, NamedBitList); encode_bit_string(C, BitListVal, NamedBitList) -> - encode_bit_string1(get_constraint(C, 'SizeConstraint'), BitListVal, NamedBitList). + encode_bit_string1(C, BitListVal, NamedBitList). %% when the value is a list of named bits encode_bit_string1(C, [FirstVal|_RestVal]=LoNB, NamedBitList) @@ -704,13 +704,20 @@ make_and_set_list([], _) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% X.691:16 -%% encode_octet_string(Constraint,Val) +%% encode_octet_string(Val) +%% encode_octet_string(Constraint, Val) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -encode_octet_string(C,Val) -> - case get_constraint(C,'SizeConstraint') of - 0 -> - <<>>; +encode_octet_string(Val) -> + try + [encode_length(length(Val)),list_to_binary(Val)] + catch + error:{error,{asn1,{encode_length,_}}} -> + encode_fragmented_octet_string(Val) + end. + +encode_octet_string(C, Val) -> + case C of 1 -> list_to_binary(Val); 2 -> @@ -736,16 +743,10 @@ encode_octet_string(C,Val) -> catch error:{error,{asn1,{encode_length,_}}} -> encode_fragmented_octet_string(Val) - end; - no -> - try - [encode_length(length(Val)),list_to_binary(Val)] - catch - error:{error,{asn1,{encode_length,_}}} -> - encode_fragmented_octet_string(Val) end end. + encode_fragmented_octet_string(Val) -> Bin = list_to_binary(Val), efos_1(Bin). |