aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/asn1/src/asn1ct_check.erl25
-rw-r--r--lib/asn1/test/asn1_SUITE_data/ValueTest.asn24
-rw-r--r--lib/asn1/test/error_SUITE.erl28
-rw-r--r--lib/asn1/test/testValueTest.erl10
4 files changed, 72 insertions, 15 deletions
diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl
index 30ec0c2aac..cc03cd68fe 100644
--- a/lib/asn1/src/asn1ct_check.erl
+++ b/lib/asn1/src/asn1ct_check.erl
@@ -2308,8 +2308,8 @@ normalize_value(S0, Type, {'DEFAULT',Value}, NameList) ->
normalize_integer(S0, Value, CType);
{'BIT STRING',CType,_} ->
normalize_bitstring(S,Value,CType);
- {'OCTET STRING',CType,_} ->
- normalize_octetstring(S0, Value, CType);
+ {'OCTET STRING',_,_} ->
+ normalize_octetstring(S0, Value);
{'NULL',_CType,_} ->
%%normalize_null(Value);
'NULL';
@@ -2451,17 +2451,26 @@ hex_to_int(D) when $A =< D, D =< $F -> D - ($A - 10).
%% {bstring,String} each element in String corresponds to one bit in an octet
%% {hstring,String} each element in String corresponds to one byte in an octet
%% #'Externalvaluereference'
-normalize_octetstring(S,Value,CType) ->
+normalize_octetstring(S, Value) ->
case Value of
{bstring,String} ->
bstring_to_binary(String);
{hstring,String} ->
hstring_to_binary(String);
- Rec when is_record(Rec,'Externalvaluereference') ->
- get_normalized_value(S,Value,CType,
- fun normalize_octetstring/3,[]);
- {Name,String} when is_atom(Name) ->
- normalize_octetstring(S,String,CType);
+ #'Externalvaluereference'{} ->
+ case get_referenced_value(S, Value) of
+ String when is_binary(String) ->
+ String;
+ Other ->
+ normalize_octetstring(S, Other)
+ end;
+ {'ValueFromObject',{object,Obj},FieldNames} ->
+ case extract_field(S, Obj, FieldNames) of
+ #valuedef{value=Val} when is_binary(Val) ->
+ Val;
+ _ ->
+ asn1_error(S, illegal_octet_string_value)
+ end;
_ ->
asn1_error(S, illegal_octet_string_value)
end.
diff --git a/lib/asn1/test/asn1_SUITE_data/ValueTest.asn b/lib/asn1/test/asn1_SUITE_data/ValueTest.asn
index 51da9d8afb..739c8a4e45 100644
--- a/lib/asn1/test/asn1_SUITE_data/ValueTest.asn
+++ b/lib/asn1/test/asn1_SUITE_data/ValueTest.asn
@@ -79,4 +79,28 @@ int-holder-2 INT-HOLDER ::= { ID 4 OBJ int-holder-1 }
II ::= INTEGER (int-from-object-1..int-from-object-2)
+-- Recursive OCTET STRING definitions.
+
+OS-HOLDER ::= CLASS {
+ &id INTEGER UNIQUE,
+ &os OCTET STRING
+} WITH SYNTAX {
+ ID &id OS &os
+}
+
+os-holder-1 OS-HOLDER ::= { ID 1 OS '4041FF'H }
+
+OctetStringSeq ::= ParamSeq{OCTET STRING}
+
+someOctetString OCTET STRING ::= '404142'H
+
+octetStringSeq1 OctetStringSeq ::= { a someOctetString }
+octetStringSeq2 OctetStringSeq ::= { a otherOctetString }
+octetStringSeq3 OctetStringSeq ::= { a os-holder-1.&os }
+
+otherOctetString OCTET STRING ::= someOctetString
+
+os-1 OCTET STRING ::= os-2
+os-2 OCTET STRING ::= os-holder-1.&os
+
END
diff --git a/lib/asn1/test/error_SUITE.erl b/lib/asn1/test/error_SUITE.erl
index 6c4920dcf7..35ca9a2f5e 100644
--- a/lib/asn1/test/error_SUITE.erl
+++ b/lib/asn1/test/error_SUITE.erl
@@ -412,6 +412,12 @@ values(Config) ->
" os2 OCTET STRING ::= 42\n"
" os3 OCTET STRING ::= { 1, 3 }\n"
" os4 OCTET STRING ::= '1234'H\n"
+ " Seq ::= SEQUENCE {\n"
+ " an OCTET STRING\n"
+ " }\n"
+ " seq Seq ::= { an int }\n"
+ " os5 OCTET STRING ::= holder-1.&str\n"
+ " os6 OCTET STRING ::= int\n"
" int1 INTEGER ::= \"string\"\n"
" int2 INTEGER ::= os4\n"
@@ -428,6 +434,8 @@ values(Config) ->
" holder-1 HOLDER ::= { &str \"xyz\" }\n"
" holder-2 HOLDER ::= { &str \"xyz\", &obj holder-1 }\n"
+
+ " int INTEGER ::= 42\n"
"END\n">>},
{error,
[
@@ -437,19 +445,25 @@ values(Config) ->
illegal_octet_string_value},
{structured_error,{M,4},asn1ct_check,
illegal_octet_string_value},
- {structured_error,{M,6},asn1ct_check,
+ {structured_error,{M,9},asn1ct_check,
+ illegal_octet_string_value},
+ {structured_error,{M,10},asn1ct_check,
+ illegal_octet_string_value},
+ {structured_error,{M,11},asn1ct_check,
+ illegal_octet_string_value},
+ {structured_error,{M,12},asn1ct_check,
illegal_integer_value},
- {structured_error,{M,7},asn1ct_check,
+ {structured_error,{M,13},asn1ct_check,
illegal_integer_value},
- {structured_error,{M,8},asn1ct_check,
+ {structured_error,{M,14},asn1ct_check,
illegal_integer_value},
- {structured_error,{M,9},asn1ct_check,
+ {structured_error,{M,15},asn1ct_check,
illegal_integer_value},
- {structured_error,{M,10},asn1ct_check,
+ {structured_error,{M,16},asn1ct_check,
illegal_integer_value},
- {structured_error,{M,11},asn1ct_check,
+ {structured_error,{M,17},asn1ct_check,
{undefined_field,'undefined-field'}},
- {structured_error,{M,12},asn1ct_check,
+ {structured_error,{M,18},asn1ct_check,
{undefined_field,'UndefinedField'}}
]
} = run(P, Config),
diff --git a/lib/asn1/test/testValueTest.erl b/lib/asn1/test/testValueTest.erl
index d9cc3de5eb..24a2862b40 100644
--- a/lib/asn1/test/testValueTest.erl
+++ b/lib/asn1/test/testValueTest.erl
@@ -72,8 +72,18 @@ main() ->
roundtrip('II', 4),
roundtrip_error('II', 5),
+ %% Recursive value definitions.
+ {'OctetStringSeq',<<16#40,16#41,16#42>>} = M:octetStringSeq1(),
+ <<16#40,16#41,16#42>> = M:otherOctetString(),
+ <<16#40,16#41,16#42>> = M:someOctetString(),
+ {'OctetStringSeq',<<16#40,16#41,16#42>>} = M:octetStringSeq2(),
+ {'OctetStringSeq',<<16#40,16#41,16#FF>>} = M:octetStringSeq3(),
+ <<16#40,16#41,16#FF>> = M:'os-1'(),
+ <<16#40,16#41,16#FF>> = M:'os-2'(),
+
ok.
+
roundtrip(T, V) ->
asn1_test_lib:roundtrip('ValueTest', T, V).