summaryrefslogtreecommitdiff
path: root/lib/asn1
diff options
context:
space:
mode:
authorBjörn Gustavsson <bjorn@erlang.org>2013-03-08 09:51:43 +0100
committerBjörn Gustavsson <bjorn@erlang.org>2013-03-08 11:36:24 +0100
commit7c1786ef06498a80f982aa08da30e3775184c5d3 (patch)
tree161f88675eb0021edde8ebbd38d799aa04e92362 /lib/asn1
parent05f11890bdfec4bfc3a78e191a87e70a937ffc54 (diff)
downloaderlang-7c1786ef06498a80f982aa08da30e3775184c5d3.tar.gz
PER/UPER: Correct decoding of ENUMERATEDs with a single value
An ENUMERATED with as single value is not encoded. The decoder incorrectly assumed that it was encoded in one bit.
Diffstat (limited to 'lib/asn1')
-rw-r--r--lib/asn1/src/asn1ct_imm.erl10
-rw-r--r--lib/asn1/test/asn1_SUITE_data/Prim.asn113
2 files changed, 19 insertions, 4 deletions
diff --git a/lib/asn1/src/asn1ct_imm.erl b/lib/asn1/src/asn1ct_imm.erl
index 869bda5d52..4b2c3b1b65 100644
--- a/lib/asn1/src/asn1ct_imm.erl
+++ b/lib/asn1/src/asn1ct_imm.erl
@@ -61,6 +61,8 @@ optimize_alignment(Imm, Al) ->
per_dec_boolean() ->
{map,{get_bits,1,[1]},[{0,false},{1,true}]}.
+per_dec_enumerated([{V,_}], _Aligned) ->
+ {value,V};
per_dec_enumerated(NamedList0, Aligned) ->
Ub = length(NamedList0) - 1,
Constraint = [{'ValueRange',{0,Ub}}],
@@ -375,6 +377,8 @@ opt_al({call,Fun,E0}, A0) ->
opt_al({convert,Op,E0}, A0) ->
{E,A} = opt_al(E0, A0),
{{convert,Op,E},A};
+opt_al({value,V}=Term, A) when is_integer(V); is_atom(V) ->
+ {Term,A};
opt_al({value,E0}, A0) ->
{E,A} = opt_al(E0, A0),
{{value,E},A};
@@ -391,8 +395,6 @@ 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}.
@@ -480,8 +482,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,V}, Buf0, St0) when is_atom(V) ->
+ {{"'"++atom_to_list(V)++"'",Buf0},[],St0};
flatten({value,V0}, Buf0, St0) when is_integer(V0) ->
{{V0,Buf0},[],St0};
flatten({value,V0}, Buf0, St0) ->
diff --git a/lib/asn1/test/asn1_SUITE_data/Prim.asn1 b/lib/asn1/test/asn1_SUITE_data/Prim.asn1
index 17a5d3490a..c3d54dbbb3 100644
--- a/lib/asn1/test/asn1_SUITE_data/Prim.asn1
+++ b/lib/asn1/test/asn1_SUITE_data/Prim.asn1
@@ -22,6 +22,8 @@ BEGIN
Enum ::= ENUMERATED {monday(1),tuesday(2),wednesday(3),thursday(4),
friday(5),saturday(6),sunday(7)}
+ SingleEnumVal ::= ENUMERATED {true}
+ SingleEnumValExt ::= ENUMERATED {true, ...}
ObjId ::= OBJECT IDENTIFIER
@@ -35,4 +37,15 @@ BEGIN
base (2),
exponent (-125..128) } )
+ Seq ::= SEQUENCE {
+ n Null,
+ i1 INTEGER (0..63),
+ e1 SingleEnumVal,
+ i2 INTEGER (0..63),
+ e2 SingleEnumVal,
+ i3 INTEGER (0..63),
+ b Bool,
+ i4 INTEGER (0..63)
+ }
+
END