aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2014-01-23 12:44:20 +0100
committerBjörn Gustavsson <[email protected]>2014-01-24 16:24:56 +0100
commit70cda04e6132a20ce1663bed5a8d7345a87103f2 (patch)
tree3a12128282c76dc7458137a508e3ee0f04564bc3 /lib/asn1/src
parentaaa4ea283b2b7dad74fdcdd5963558e9d03d80b0 (diff)
downloadotp-70cda04e6132a20ce1663bed5a8d7345a87103f2.tar.gz
otp-70cda04e6132a20ce1663bed5a8d7345a87103f2.tar.bz2
otp-70cda04e6132a20ce1663bed5a8d7345a87103f2.zip
Fix open types
Diffstat (limited to 'lib/asn1/src')
-rw-r--r--lib/asn1/src/asn1ct_constructed_per.erl22
-rw-r--r--lib/asn1/src/asn1ct_gen_ber_bin_v2.erl80
-rw-r--r--lib/asn1/src/asn1rtt_per_common.erl13
3 files changed, 82 insertions, 33 deletions
diff --git a/lib/asn1/src/asn1ct_constructed_per.erl b/lib/asn1/src/asn1ct_constructed_per.erl
index f2509d1324..ed3f6f886e 100644
--- a/lib/asn1/src/asn1ct_constructed_per.erl
+++ b/lib/asn1/src/asn1ct_constructed_per.erl
@@ -450,8 +450,13 @@ dec_objset_default(N, C, LeadingAttr, false) ->
"{value,Bytes},"
"{unique_name_and_value,",{asis,LeadingAttr},",Id}}}).",nl,nl]);
dec_objset_default(N, _, _, true) ->
- emit([{asis,N},"(Bytes, Id) ->",nl,
- "Bytes.",nl,nl]).
+ emit([{asis,N},"(Bytes, Id) ->",nl|
+ case asn1ct:use_legacy_types() of
+ false ->
+ ["{asn1_OPENTYPE,Bytes}.",nl,nl];
+ true ->
+ ["Bytes.",nl,nl]
+ end]).
dec_objset_1(Erule, N, {Id,Obj}, RestFields, Typename) ->
emit([{asis,N},"(Bytes, ",{asis,Id},") ->",nl]),
@@ -1069,8 +1074,17 @@ enc_objset_imm(Erule, Component, ObjSet, RestFieldNames, Extensible) ->
enc_obj(Erule, Obj, RestFieldNames, Aligned)] ||
{Key,Obj} <- ObjSet] ++
[['_',case Extensible of
- false -> E;
- true -> {put_bits,{var,"Val"},binary,[1]}
+ false ->
+ E;
+ true ->
+ case asn1ct:use_legacy_types() of
+ false ->
+ {call,per_common,open_type_to_binary,
+ [{var,"Val"}]};
+ true ->
+ {call,per_common,legacy_open_type_to_binary,
+ [{var,"Val"}]}
+ end
end]]}].
enc_obj(Erule, Obj, RestFieldNames0, Aligned) ->
diff --git a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
index f3a6f115d3..bea0ec8968 100644
--- a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
+++ b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
@@ -1124,13 +1124,11 @@ gen_objset_enc(Erules, ObjSetName, UniqueName,
%% See X.681 Annex E for the following case
gen_objset_enc(_,ObjSetName,_UniqueName,['EXTENSIONMARK'],_ClName,
_ClFields,_NthObj,Acc) ->
- emit(["'getenc_",ObjSetName,"'(_) ->",nl]),
- emit({indent(3),"fun(_, Val, _RestPrimFieldName) ->",nl}),
- emit({indent(6),"Len = case Val of",nl,indent(9),
- "Bin when is_binary(Bin) -> byte_size(Bin);",nl,indent(9),
- "_ -> length(Val)",nl,indent(6),"end,"}),
- emit({indent(6),"{Val,Len}",nl}),
- emit({indent(3),"end.",nl,nl}),
+ emit(["'getenc_",ObjSetName,"'(_) ->",nl,
+ indent(2),"fun(_, Val, _RestPrimFieldName) ->",nl]),
+ emit_enc_open_type(4),
+ emit([nl,
+ indent(2),"end.",nl,nl]),
Acc;
gen_objset_enc(_, ObjSetName, UniqueName, [], _, _, _, Acc) ->
emit_default_getenc(ObjSetName, UniqueName),
@@ -1192,13 +1190,8 @@ gen_inlined_enc_funs1(Fields, [{typefield,Name,_}|Rest], ObjSetName,
%% were no type in the table and we therefore generate
%% code that returns the input for application
%% treatment.
- emit([indent(9),{asis,Name}," ->",nl,
- indent(12),"Len = case Val of",nl,
- indent(15),"Bin when is_binary(Bin) -> "
- "byte_size(Bin);",nl,
- indent(15),"_ -> length(Val)",nl,
- indent(12),"end,",nl,
- indent(12),"{Val,Len}"]),
+ emit([indent(9),{asis,Name}," ->",nl]),
+ emit_enc_open_type(11),
{Acc0,0}
end,
gen_inlined_enc_funs1(Fields, Rest, ObjSetName, Sep, NthObj+NAdd, Acc);
@@ -1209,6 +1202,25 @@ gen_inlined_enc_funs1(_, [], _, _, NthObj, Acc) ->
indent(3),"end"]),
{Acc,NthObj}.
+emit_enc_open_type(I) ->
+ Indent = indent(I),
+ S = [Indent, "case Val of",nl,
+ Indent,indent(2),"{asn1_OPENTYPE,Bin} when is_binary(Bin) ->",nl,
+ Indent,indent(4),"{Bin,byte_size(Bin)}"|
+ case asn1ct:use_legacy_types() of
+ false ->
+ [nl,
+ Indent,"end"];
+ true ->
+ [";",nl,
+ Indent,indent(2),"Bin when is_binary(Bin) ->",nl,
+ Indent,indent(4),"{Bin,byte_size(Bin)};",nl,
+ Indent,indent(2),"_ ->",nl,
+ Indent,indent(4),"{Val,length(Val)}",nl,
+ Indent, "end"]
+ end],
+ emit(S).
+
emit_inner_of_fun(TDef=#typedef{name={ExtMod,Name},typespec=Type},
InternalDefFunName) ->
OTag = Type#type.tag,
@@ -1292,14 +1304,9 @@ gen_objset_dec(_,ObjSetName,_UniqueName,['EXTENSIONMARK'],_ClName,
_ClFields,_NthObj) ->
emit(["'getdec_",ObjSetName,"'(_) ->",nl]),
emit([indent(2),"fun(_,Bytes, _RestPrimFieldName) ->",nl]),
-
- emit([indent(4),"case Bytes of",nl,
- indent(6),"Bin when is_binary(Bin) -> ",nl,
- indent(8),"Bin;",nl,
- indent(6),"_ ->",nl,
- indent(8),{call,ber,ber_encode,["Bytes"]},nl,
- indent(4),"end",nl]),
- emit([indent(2),"end.",nl,nl]),
+ emit_dec_open_type(4),
+ emit([nl,
+ indent(2),"end.",nl,nl]),
ok;
gen_objset_dec(_, ObjSetName, UniqueName, [], _, _, _) ->
emit_default_getdec(ObjSetName, UniqueName),
@@ -1346,12 +1353,8 @@ gen_inlined_dec_funs1(Fields, [{typefield,Name,Prop}|Rest],
end,
0;
false ->
- emit([indent(9),{asis,Name}," ->",nl,
- indent(12),"Len = case Bytes of",nl,
- indent(15),"B when is_binary(B) -> byte_size(B);",nl,
- indent(15),"_ -> length(Bytes)",nl,
- indent(12),"end,",nl,
- indent(12),"{Bytes,[],Len}"]),
+ emit([indent(9),{asis,Name}," ->",nl]),
+ emit_dec_open_type(11),
0
end,
gen_inlined_dec_funs1(Fields, Rest, ObjSetName, Sep, NthObj+N);
@@ -1362,6 +1365,27 @@ gen_inlined_dec_funs1(_, [], _, _, NthObj) ->
indent(3),"end"]),
NthObj.
+emit_dec_open_type(I) ->
+ Indent = indent(I),
+ S = case asn1ct:use_legacy_types() of
+ false ->
+ [Indent, "case Bytes of",nl,
+ Indent,indent(2),"Bin when is_binary(Bin) -> ",nl,
+ Indent,indent(4),"{asn1_OPENTYPE,Bin};",nl,
+ Indent,indent(2),"_ ->",nl,
+ Indent,indent(4),"{asn1_OPENTYPE,",
+ {call,ber,ber_encode,["Bytes"]},"}",nl,
+ Indent, "end"];
+ true ->
+ [Indent, "case Bytes of",nl,
+ Indent,indent(2),"Bin when is_binary(Bin) -> ",nl,
+ Indent,indent(4),"Bin;",nl,
+ Indent,indent(2),"_ ->",nl,
+ Indent,indent(4),{call,ber,ber_encode,["Bytes"]},nl,
+ Indent, "end"]
+ end,
+ emit(S).
+
emit_inner_of_decfun(#typedef{name={ExtName,Name},typespec=Type},Prop,
InternalDefFunName) ->
OTag = Type#type.tag,
diff --git a/lib/asn1/src/asn1rtt_per_common.erl b/lib/asn1/src/asn1rtt_per_common.erl
index e84fa581df..71fec411a0 100644
--- a/lib/asn1/src/asn1rtt_per_common.erl
+++ b/lib/asn1/src/asn1rtt_per_common.erl
@@ -39,7 +39,8 @@
to_named_bitstring/1,to_named_bitstring/2,
bs_drop_trailing_zeroes/1,adjust_trailing_zeroes/2,
is_default_bitstring/3,is_default_bitstring/5,
- extension_bitmap/3]).
+ extension_bitmap/3,
+ open_type_to_binary/1,legacy_open_type_to_binary/1]).
-define('16K',16384).
@@ -326,6 +327,16 @@ is_default_bitstring(_, _, _, _, _) -> false.
extension_bitmap(Val, Pos, Limit) ->
extension_bitmap(Val, Pos, Limit, 0).
+open_type_to_binary({asn1_OPENTYPE,Bin}) when is_binary(Bin) ->
+ Bin.
+
+legacy_open_type_to_binary({asn1_OPENTYPE,Bin}) when is_binary(Bin) ->
+ Bin;
+legacy_open_type_to_binary(Bin) when is_binary(Bin) ->
+ Bin;
+legacy_open_type_to_binary(List) when is_list(List) ->
+ List.
+
%%%
%%% Internal functions.
%%%