aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/asn1/src')
-rw-r--r--lib/asn1/src/asn1ct_constructed_per.erl19
-rw-r--r--lib/asn1/src/asn1ct_gen_per.erl52
-rw-r--r--lib/asn1/src/asn1ct_imm.erl4
-rw-r--r--lib/asn1/src/asn1rtt_per.erl47
-rw-r--r--lib/asn1/src/asn1rtt_per_common.erl24
-rw-r--r--lib/asn1/src/asn1rtt_uper.erl51
6 files changed, 58 insertions, 139 deletions
diff --git a/lib/asn1/src/asn1ct_constructed_per.erl b/lib/asn1/src/asn1ct_constructed_per.erl
index c3aa482051..3c59c73108 100644
--- a/lib/asn1/src/asn1ct_constructed_per.erl
+++ b/lib/asn1/src/asn1ct_constructed_per.erl
@@ -1518,7 +1518,6 @@ gen_dec_line_dec_inf(Comp, DecInfObj) ->
gen_dec_line_other(Erule, Atype, TopType, Comp) ->
#'ComponentType'{name=Cname,typespec=Type} = Comp,
CurrMod = get(currmod),
- Ctgenmod = asn1ct_gen:ct_gen_module(Erule),
case asn1ct_gen:type(Atype) of
#'Externaltypereference'{module=CurrMod,type=EType} ->
fun(BytesVar) ->
@@ -1532,16 +1531,16 @@ gen_dec_line_other(Erule, Atype, TopType, Comp) ->
{primitive,bif} ->
case Atype of
{fixedtypevaluefield,_,Btype} ->
- gen_dec_prim(Ctgenmod, Erule, Btype);
+ asn1ct_gen_per:gen_dec_imm(Erule, Btype);
_ ->
- gen_dec_prim(Ctgenmod, Erule, Type)
+ asn1ct_gen_per:gen_dec_imm(Erule, Type)
end;
'ASN1_OPEN_TYPE' ->
case Type#type.def of
#'ObjectClassFieldType'{type=OpenType} ->
- gen_dec_prim(Ctgenmod, Erule, #type{def=OpenType});
+ asn1ct_gen_per:gen_dec_imm(Erule, #type{def=OpenType});
_ ->
- gen_dec_prim(Ctgenmod, Erule, Type)
+ asn1ct_gen_per:gen_dec_imm(Erule, Type)
end;
#typereference{val=Dname} ->
fun(BytesVar) ->
@@ -1567,16 +1566,6 @@ gen_dec_line_other(Erule, Atype, TopType, Comp) ->
end
end.
-gen_dec_prim(Ctgenmod, Erule, Type) ->
- case asn1ct_gen_per:gen_dec_imm(Erule, Type) of
- no ->
- fun(BytesVar) ->
- Ctgenmod:gen_dec_prim(Erule, Type, BytesVar)
- end;
- Imm ->
- Imm
- end.
-
gen_enc_choice(Erule,TopType,CompList,Ext) ->
gen_enc_choice_tag(Erule, CompList, [], Ext),
emit({com,nl}),
diff --git a/lib/asn1/src/asn1ct_gen_per.erl b/lib/asn1/src/asn1ct_gen_per.erl
index ddfa39486a..c7509b57af 100644
--- a/lib/asn1/src/asn1ct_gen_per.erl
+++ b/lib/asn1/src/asn1ct_gen_per.erl
@@ -1119,6 +1119,8 @@ gen_dec_imm_1({'BIT STRING',NNL}, Constr0, Aligned) ->
end,
{call,D,Imm}
end;
+gen_dec_imm_1('NULL', _Constr, _Aligned) ->
+ {value,'NULL'};
gen_dec_imm_1('BOOLEAN', _Constr, _Aligned) ->
asn1ct_imm:per_dec_boolean();
gen_dec_imm_1({'ENUMERATED',{Base,Ext}}, _Constr, Aligned) ->
@@ -1163,11 +1165,29 @@ gen_dec_imm_1('GeneralString', _Constraint, Aligned) ->
gen_dec_restricted_string(Aligned);
gen_dec_imm_1('ObjectDescriptor', _Constraint, Aligned) ->
gen_dec_restricted_string(Aligned);
+gen_dec_imm_1('OBJECT IDENTIFIER', _Constraint, Aligned) ->
+ Dec = fun(V, Buf) ->
+ emit(["{",{call,per_common,decode_oid,[V]},com,
+ Buf,"}"])
+ end,
+ {call,Dec,gen_dec_restricted_string(Aligned)};
+gen_dec_imm_1('RELATIVE-OID', _Constraint, Aligned) ->
+ Dec = fun(V, Buf) ->
+ emit(["{",{call,per_common,decode_relative_oid,[V]},com,
+ Buf,"}"])
+ end,
+ {call,Dec,gen_dec_restricted_string(Aligned)};
gen_dec_imm_1('UTF8String', _Constraint, Aligned) ->
asn1ct_imm:per_dec_restricted_string(Aligned);
gen_dec_imm_1('REAL', _Constraint, Aligned) ->
asn1ct_imm:per_dec_real(Aligned);
-gen_dec_imm_1(_, _, _) -> no.
+gen_dec_imm_1(#'ObjectClassFieldType'{}=TypeName, Constraint, Aligned) ->
+ case asn1ct_gen:get_inner(TypeName) of
+ {fixedtypevaluefield,_,InnerType} ->
+ gen_dec_imm_1(InnerType, Constraint, Aligned);
+ T ->
+ gen_dec_imm_1(T, Constraint, Aligned)
+ end.
gen_dec_bit_string(F, Imm) ->
D = fun(V, Buf) ->
@@ -1189,34 +1209,8 @@ gen_dec_restricted_string(Aligned) ->
{convert,binary_to_list,Imm}.
gen_dec_prim(Erule, Type, BytesVar) ->
- case gen_dec_imm(Erule, Type) of
- no ->
- gen_dec_prim_1(Erule, Type, BytesVar);
- Imm ->
- asn1ct_imm:dec_code_gen(Imm, BytesVar)
- end.
-
-gen_dec_prim_1(Erule,
- #type{def=Typename}=Att,
- BytesVar) ->
- case Typename of
- 'NULL' ->
- emit({"{'NULL',",BytesVar,"}"});
- 'OBJECT IDENTIFIER' ->
- call(Erule, decode_object_identifier, [BytesVar]);
- 'RELATIVE-OID' ->
- call(Erule, decode_relative_oid, [BytesVar]);
- #'ObjectClassFieldType'{} ->
- case asn1ct_gen:get_inner(Typename) of
- {fixedtypevaluefield,_,InnerType} ->
- gen_dec_prim(Erule, InnerType, BytesVar);
- T ->
- gen_dec_prim(Erule, Att#type{def=T}, BytesVar)
- end;
- Other ->
- exit({'cant decode' ,Other})
- end.
-
+ Imm = gen_dec_imm(Erule, Type),
+ asn1ct_imm:dec_code_gen(Imm, BytesVar).
is_already_generated(Operation,Name) ->
case get(class_default_type) of
diff --git a/lib/asn1/src/asn1ct_imm.erl b/lib/asn1/src/asn1ct_imm.erl
index 87eadac073..5bdaed8f4f 100644
--- a/lib/asn1/src/asn1ct_imm.erl
+++ b/lib/asn1/src/asn1ct_imm.erl
@@ -391,6 +391,8 @@ opt_al({'case',Cs0}, A0) ->
opt_al({map,E0,Cs}, A0) ->
{E,A} = opt_al(E0, A0),
{{map,E,Cs},A};
+opt_al('NULL'=Null, A) ->
+ {Null,A};
opt_al(I, A) when is_integer(I) ->
{I,A}.
@@ -478,6 +480,8 @@ flatten({map,E0,Cs0}, Buf0, St0) ->
{Dst,St2} = new_var("Int", St1),
Cs = flatten_map_cs(Cs0, E),
{{Dst,DstBuf},Pre++[{'map',E,Cs,{Dst,DstBuf}}],St2};
+flatten({value,'NULL'}, Buf0, St0) ->
+ {{"'NULL'",Buf0},[],St0};
flatten({value,V0}, Buf0, St0) when is_integer(V0) ->
{{V0,Buf0},[],St0};
flatten({value,V0}, Buf0, St0) ->
diff --git a/lib/asn1/src/asn1rtt_per.erl b/lib/asn1/src/asn1rtt_per.erl
index 2bcf459330..7194e8d127 100644
--- a/lib/asn1/src/asn1rtt_per.erl
+++ b/lib/asn1/src/asn1rtt_per.erl
@@ -26,8 +26,8 @@
encode_length/1,
encode_length/2,
encode_bit_string/3,
- encode_object_identifier/1, decode_object_identifier/1,
- encode_relative_oid/1, decode_relative_oid/1,
+ encode_object_identifier/1,
+ encode_relative_oid/1,
complete/1,
encode_open_type/1,
encode_GeneralString/2,
@@ -134,12 +134,6 @@ getoctets_as_bin(Bin,Num) when is_bitstring(Bin) ->
<<_:AlignBits,Val:Num/binary,RestBin/binary>> = Bin,
{Val,RestBin}.
-
-%% same as above but returns octets as a List
-getoctets_as_list(Buffer,Num) ->
- {Bin,Buffer2} = getoctets_as_bin(Buffer,Num),
- {binary_to_list(Bin),Buffer2}.
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% set_choice(Alt,Choices,Altnum) -> ListofBitSettings
%% Alt = atom()
@@ -977,33 +971,6 @@ e_o_e(Num) when Num < 128 ->
e_o_e(Num) ->
[e_o_e(Num bsr 7)|[(Num band 2#1111111) bor 2#10000000]].
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% decode_object_identifier(Bytes) -> {ObjId,RemainingBytes}
-%% ObjId -> {integer(),integer(),...} % at least 2 integers
-%% RemainingBytes -> [integer()] when integer() (0..255)
-decode_object_identifier(Bytes) ->
- {Len,Bytes2} = decode_length(Bytes,undefined),
- {Octs,Bytes3} = getoctets_as_list(Bytes2,Len),
- [First|Rest] = dec_subidentifiers(Octs,0,[]),
- Idlist = if
- First < 40 ->
- [0,First|Rest];
- First < 80 ->
- [1,First - 40|Rest];
- true ->
- [2,First - 80|Rest]
- end,
- {list_to_tuple(Idlist),Bytes3}.
-
-dec_subidentifiers([H|T],Av,Al) when H >=16#80 ->
- dec_subidentifiers(T,(Av bsl 7) + (H band 16#7F),Al);
-dec_subidentifiers([H|T],Av,Al) ->
- dec_subidentifiers(T,0,[(Av bsl 7) + H |Al]);
-dec_subidentifiers([],_Av,Al) ->
- lists:reverse(Al).
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% encode_relative_oid(Val) -> CompleteList
%% encode_relative_oid({Name,Val}) -> CompleteList
@@ -1014,16 +981,6 @@ encode_relative_oid(Val) when is_list(Val) ->
Sz = byte_size(Octets),
[encode_length(Sz)|octets_to_complete(Sz, Octets)].
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% decode_relative_oid(Val) -> CompleteList
-%% decode_relative_oid({Name,Val}) -> CompleteList
-decode_relative_oid(Bytes) ->
- {Len,Bytes2} = decode_length(Bytes,undefined),
- {Octs,Bytes3} = getoctets_as_list(Bytes2,Len),
- ObjVals = dec_subidentifiers(Octs,0,[]),
- {list_to_tuple(ObjVals),Bytes3}.
-
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% complete(InList) -> ByteList
%% Takes a coded list with bits and bytes and converts it to a list of bytes
diff --git a/lib/asn1/src/asn1rtt_per_common.erl b/lib/asn1/src/asn1rtt_per_common.erl
index cd6e9e2c99..a7d359a288 100644
--- a/lib/asn1/src/asn1rtt_per_common.erl
+++ b/lib/asn1/src/asn1rtt_per_common.erl
@@ -27,7 +27,8 @@
decode_named_bit_string/2,
decode_chars/2,decode_chars/3,
decode_chars_16bit/1,
- decode_big_chars/2]).
+ decode_big_chars/2,
+ decode_oid/1,decode_relative_oid/1]).
-define('16K',16384).
@@ -74,6 +75,20 @@ decode_chars_16bit(Val) ->
decode_big_chars(Val, N) ->
decode_big_chars_1(decode_chars(Val, N)).
+decode_oid(Octets) ->
+ [First|Rest] = dec_subidentifiers(Octets, 0, []),
+ Idlist = if
+ First < 40 ->
+ [0,First|Rest];
+ First < 80 ->
+ [1,First - 40|Rest];
+ true ->
+ [2,First - 80|Rest]
+ end,
+ list_to_tuple(Idlist).
+
+decode_relative_oid(Octets) ->
+ list_to_tuple(dec_subidentifiers(Octets, 0, [])).
%%%
%%% Internal functions.
@@ -102,3 +117,10 @@ decode_big_chars_1([H|T]) when H < 256 ->
decode_big_chars_1([H|T]) ->
[list_to_tuple(binary_to_list(<<H:32>>))|decode_big_chars_1(T)];
decode_big_chars_1([]) -> [].
+
+dec_subidentifiers([H|T], Av, Al) when H >=16#80 ->
+ dec_subidentifiers(T, (Av bsl 7) bor (H band 16#7F), Al);
+dec_subidentifiers([H|T], Av, Al) ->
+ dec_subidentifiers(T, 0, [(Av bsl 7) bor H|Al]);
+dec_subidentifiers([], _Av, Al) ->
+ lists:reverse(Al).
diff --git a/lib/asn1/src/asn1rtt_uper.erl b/lib/asn1/src/asn1rtt_uper.erl
index fa4f08363b..d78116cc92 100644
--- a/lib/asn1/src/asn1rtt_uper.erl
+++ b/lib/asn1/src/asn1rtt_uper.erl
@@ -28,8 +28,8 @@
encode_length/1, encode_length/2,
encode_bit_string/3]).
-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,
+ encode_relative_oid/1,
+ encode_object_identifier/1,
complete/1, complete_NFP/1]).
-export([encode_open_type/1]).
@@ -146,17 +146,6 @@ getoctets(Buffer, Num) when is_bitstring(Buffer) ->
<<Val:Num/integer-unit:8,RestBitStr/bitstring>> = Buffer,
{Val,RestBitStr}.
-%% Pick the first Num octets.
-%% Returns octets as a binary
-getoctets_as_bin(Bin,Num) when is_bitstring(Bin) ->
- <<Octets:Num/binary,RestBin/bitstring>> = Bin,
- {Octets,RestBin}.
-
-%% same as above but returns octets as a List
-getoctets_as_list(Buffer,Num) ->
- {Bin,Buffer2} = getoctets_as_bin(Buffer, Num),
- {binary_to_list(Bin),Buffer2}.
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% set_choice(Alt,Choices,Altnum) -> ListofBitSettings
%% Alt = atom()
@@ -1014,32 +1003,6 @@ e_o_e(Num) ->
[e_o_e(Num bsr 7)|[(Num band 2#1111111) bor 2#10000000]].
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% decode_object_identifier(Bytes) -> {ObjId,RemainingBytes}
-%% ObjId -> {integer(),integer(),...} % at least 2 integers
-%% RemainingBytes -> [integer()] when integer() (0..255)
-decode_object_identifier(Bytes) ->
- {Len,Bytes2} = decode_length(Bytes,undefined),
- {Octs,Bytes3} = getoctets_as_list(Bytes2,Len),
- [First|Rest] = dec_subidentifiers(Octs,0,[]),
- Idlist = if
- First < 40 ->
- [0,First|Rest];
- First < 80 ->
- [1,First - 40|Rest];
- true ->
- [2,First - 80|Rest]
- end,
- {list_to_tuple(Idlist),Bytes3}.
-
-dec_subidentifiers([H|T],Av,Al) when H >=16#80 ->
- dec_subidentifiers(T, (Av bsl 7) + (H band 16#7F),Al);
-dec_subidentifiers([H|T],Av,Al) ->
- dec_subidentifiers(T,0, [(Av bsl 7) + H |Al]);
-dec_subidentifiers([],_Av,Al) ->
- lists:reverse(Al).
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% encode_relative_oid(Val) -> CompleteList
%% encode_relative_oid({Name,Val}) -> CompleteList
@@ -1050,16 +1013,6 @@ encode_relative_oid(Val) when is_list(Val) ->
[encode_length(byte_size(Octets)),Octets].
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% decode_relative_oid(Val) -> CompleteList
-%% decode_relative_oid({Name,Val}) -> CompleteList
-decode_relative_oid(Bytes) ->
- {Len,Bytes2} = decode_length(Bytes,undefined),
- {Octs,Bytes3} = getoctets_as_list(Bytes2,Len),
- ObjVals = dec_subidentifiers(Octs,0,[]),
- {list_to_tuple(ObjVals),Bytes3}.
-
-
get_constraint([{Key,V}],Key) ->
V;
get_constraint([],_Key) ->