aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/asn1/src/asn1ct_gen_ber_bin_v2.erl')
-rw-r--r--lib/asn1/src/asn1ct_gen_ber_bin_v2.erl122
1 files changed, 90 insertions, 32 deletions
diff --git a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
index de81259fcb..bea0ec8968 100644
--- a/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
+++ b/lib/asn1/src/asn1ct_gen_ber_bin_v2.erl
@@ -206,10 +206,32 @@ gen_encode_prim(_Erules, #type{}=D, DoTag, Value) ->
{call,ber,encode_tags,
[DoTag,{curr,realval},{curr,realsize}]},nl,
"end"]);
+ {'BIT STRING',[]} ->
+ case asn1ct:use_legacy_types() of
+ false when BitStringConstraint =:= [] ->
+ call(encode_unnamed_bit_string, [Value,DoTag]);
+ false ->
+ call(encode_unnamed_bit_string,
+ [{asis,BitStringConstraint},Value,DoTag]);
+ true ->
+ call(encode_bit_string,
+ [{asis,BitStringConstraint},Value,
+ {asis,[]},DoTag])
+ end;
{'BIT STRING',NamedNumberList} ->
- call(encode_bit_string,
- [{asis,BitStringConstraint},Value,
- {asis,NamedNumberList},DoTag]);
+ case asn1ct:use_legacy_types() of
+ false when BitStringConstraint =:= [] ->
+ call(encode_named_bit_string,
+ [Value,{asis,NamedNumberList},DoTag]);
+ false ->
+ call(encode_named_bit_string,
+ [{asis,BitStringConstraint},Value,
+ {asis,NamedNumberList},DoTag]);
+ true ->
+ call(encode_bit_string,
+ [{asis,BitStringConstraint},Value,
+ {asis,NamedNumberList},DoTag])
+ end;
'NULL' ->
call(encode_null, [Value,DoTag]);
'OBJECT IDENTIFIER' ->
@@ -471,7 +493,6 @@ gen_dec_prim(_Erules, Att, BytesVar, DoTag, _TagIn, _Form, _OptOrMand) ->
_ -> ""
end,
NewTypeName = case Typename of
- 'OCTET STRING' -> restricted_string;
'NumericString' -> restricted_string;
'TeletexString' -> restricted_string;
'T61String' -> restricted_string;
@@ -529,6 +550,19 @@ gen_dec_prim(_Erules, Att, BytesVar, DoTag, _TagIn, _Form, _OptOrMand) ->
'RELATIVE-OID' ->
emit(["decode_relative_oid(",BytesVar,","]),
need(decode_relative_oid, 2);
+ 'OCTET STRING' ->
+ F = case asn1ct:use_legacy_types() of
+ false -> decode_octet_string;
+ true -> decode_restricted_string
+ end,
+ emit([{asis,F},"(",BytesVar,","]),
+ case Constraint of
+ [] ->
+ need(F, 2);
+ _ ->
+ emit([{asis,Constraint},","]),
+ need(F, 3)
+ end;
restricted_string ->
emit(["decode_restricted_string",AsBin,"(",BytesVar,","]),
case Constraint of
@@ -1090,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),
@@ -1158,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);
@@ -1175,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,
@@ -1258,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),
@@ -1312,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);
@@ -1328,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,