From 1a891ebb4644ed7db9729b1659a21553d3431bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 28 Feb 2013 08:41:22 +0100 Subject: testConstraints: Add more tests of SIZE constraints --- lib/asn1/test/testConstraints.erl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib/asn1/test/testConstraints.erl') diff --git a/lib/asn1/test/testConstraints.erl b/lib/asn1/test/testConstraints.erl index c8d9008641..ef6c1b3486 100644 --- a/lib/asn1/test/testConstraints.erl +++ b/lib/asn1/test/testConstraints.erl @@ -128,7 +128,20 @@ int_constraints(Rules) -> %%========================================================== roundtrip('T', "IA"), - roundtrip('T2', "IA"). + roundtrip('T2', "IA"), + + %%========================================================== + %% More SIZE Constraints + %%========================================================== + + roundtrip('FixedSize', "0123456789"), + roundtrip('FixedSize2', "0123456789"), + roundtrip('FixedSize2', "0123456789abcdefghij"), + + [roundtrip('VariableSize', lists:seq($A, $A+L-1)) || + L <- lists:seq(1, 10)], + + ok. refed_NNL_name(_Erule) -> ?line {ok,_} = asn1_wrapper:encode('Constraints','AnotherThing',fred), -- cgit v1.2.3 From 902b51b8b43fe66fd4488c7fa10c05c3b9da59b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 28 Feb 2013 11:42:47 +0100 Subject: PER/UPER: Correct encoding of a length outside the root range Consider a type with a size constraint with an extension marker such as: S ::= OCTET STRING (SIZE (0..10, ...)) For a length outside the root range (e.g. 42), the PER/UPER encoder will encode the length field in the same way as it would the type INTEGER (0..MAX) (i.e., as semi-constrained whole number), while the decoder would decode the length in the same way as length field without any constraint. Clearly, either the encoder or the decoder is wrong. But which one? Dubuisson's [1] book (page 442) says that the length should be encoded as a semi-constrained whole number if the length is outside the root range. The X.691 standard document [2] also says (e.g. in 15.11) that length fields should be a semi-constrained number, but gives a reference to section gives a reference to section 10.9, "General rules for encoding a length determinant", and not to to 10.7, "Encoding of a semi-constrained whole number". Reading the standard that way should imply that a length outside the root range should be encoded in the same way as an unconstrained length, and that the decoder does the right thing. Further support for that interpretation: - Larmouth's book [3], page 303. - The ASN.1 playground. [4] References: [1] http://www.oss.com/asn1/resources/books-whitepapers-pubs/dubuisson-asn1-book.PDF [2] http://www.itu.int/ITU-T/studygroups/com17/languages/X.691-0207.pdf [3] http://www.oss.com/asn1/resources/books-whitepapers-pubs/larmouth-asn1-book.pdf [4] http://asn1-playground.oss.com --- lib/asn1/test/testConstraints.erl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/asn1/test/testConstraints.erl') diff --git a/lib/asn1/test/testConstraints.erl b/lib/asn1/test/testConstraints.erl index ef6c1b3486..d6db1c2b91 100644 --- a/lib/asn1/test/testConstraints.erl +++ b/lib/asn1/test/testConstraints.erl @@ -128,7 +128,11 @@ int_constraints(Rules) -> %%========================================================== roundtrip('T', "IA"), + roundtrip('T', "IAB"), + roundtrip('T', "IABC"), roundtrip('T2', "IA"), + roundtrip('T2', "IAB"), + roundtrip('T2', "IABC"), %%========================================================== %% More SIZE Constraints -- cgit v1.2.3 From 95af544936f9b6d7b8d03f3f49effaf5c314513d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 28 Feb 2013 15:09:06 +0100 Subject: Correct encoding (decoding) of lengths less than the root range Given the type: S ::= IA5String (SIZE (5, ...)) attempting to encode (to PER/UPER) a string shorter than 5 characters would fail. Similarly, attempting to decode such string in the BER format would fail. In the case of BER, we can do no range checks if the size constraint is extensible. --- lib/asn1/test/testConstraints.erl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/asn1/test/testConstraints.erl') diff --git a/lib/asn1/test/testConstraints.erl b/lib/asn1/test/testConstraints.erl index d6db1c2b91..d245f6d1d5 100644 --- a/lib/asn1/test/testConstraints.erl +++ b/lib/asn1/test/testConstraints.erl @@ -145,8 +145,16 @@ int_constraints(Rules) -> [roundtrip('VariableSize', lists:seq($A, $A+L-1)) || L <- lists:seq(1, 10)], + roundtrip_enc('ShorterExt', "a", shorter_ext(Rules, "a")), + roundtrip('ShorterExt', "abcde"), + roundtrip('ShorterExt', "abcdef"), + ok. +shorter_ext(per, "a") -> <<16#80,16#01,16#61>>; +shorter_ext(uper, "a") -> <<16#80,16#E1>>; +shorter_ext(ber, _) -> none. + refed_NNL_name(_Erule) -> ?line {ok,_} = asn1_wrapper:encode('Constraints','AnotherThing',fred), ?line {error,_Reason} = @@ -160,6 +168,15 @@ roundtrip(Module, Type, Value) -> {ok,Value} = Module:decode(Type, Encoded), ok. +roundtrip_enc(Type, Value, Enc) -> + Module = 'Constraints', + {ok,Encoded} = Module:encode(Type, Value), + {ok,Value} = Module:decode(Type, Encoded), + case Enc of + none -> ok; + Encoded -> ok + end. + range_error(ber, Type, Value) -> %% BER: Values outside the effective range should be rejected %% on decode. -- cgit v1.2.3 From 53022b787c723a6c4cdf153f5705bde5fb4655ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Sat, 2 Mar 2013 12:46:37 +0100 Subject: Normalize SIZE constraints to simplify backends --- lib/asn1/test/testConstraints.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/asn1/test/testConstraints.erl') diff --git a/lib/asn1/test/testConstraints.erl b/lib/asn1/test/testConstraints.erl index d245f6d1d5..fc217e45f7 100644 --- a/lib/asn1/test/testConstraints.erl +++ b/lib/asn1/test/testConstraints.erl @@ -142,6 +142,9 @@ int_constraints(Rules) -> roundtrip('FixedSize2', "0123456789"), roundtrip('FixedSize2', "0123456789abcdefghij"), + range_error(Rules, 'FixedSize', "short"), + range_error(Rules, 'FixedSize2', "short"), + [roundtrip('VariableSize', lists:seq($A, $A+L-1)) || L <- lists:seq(1, 10)], @@ -181,7 +184,7 @@ range_error(ber, Type, Value) -> %% BER: Values outside the effective range should be rejected %% on decode. {ok,Encoded} = 'Constraints':encode(Type, Value), - {error,{asn1,{integer_range,_,_}}} = 'Constraints':decode(Type, Encoded), + {error,{asn1,_}} = 'Constraints':decode(Type, Encoded), ok; range_error(Per, Type, Value) when Per =:= per; Per =:= uper -> %% (U)PER: Values outside the effective range should be rejected -- cgit v1.2.3 From a1495bd1e09dbefa8595e9388140140c143088f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 16 Apr 2013 10:40:32 +0200 Subject: PER/UPER: Fix decoding of semi-constrained INTEGERs A semi-constrained INTEGER with a non-zero lower bound would be incorrectly decoded. This bug was introduced in R16. --- lib/asn1/test/testConstraints.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/asn1/test/testConstraints.erl') diff --git a/lib/asn1/test/testConstraints.erl b/lib/asn1/test/testConstraints.erl index fc217e45f7..b90ae8cab2 100644 --- a/lib/asn1/test/testConstraints.erl +++ b/lib/asn1/test/testConstraints.erl @@ -121,6 +121,16 @@ int_constraints(Rules) -> roundtrip('X1', 20), range_error(Rules, 'X1', 21), + %%========================================================== + %% SemiConstrained + %%========================================================== + + roundtrip('SemiConstrained', 100), + roundtrip('SemiConstrained', 397249742397243), + roundtrip('NegSemiConstrained', -128), + roundtrip('NegSemiConstrained', -1), + roundtrip('NegSemiConstrained', 500), + %%========================================================== %% SIZE Constraint (Duboisson p. 268) %% T ::= IA5String (SIZE (1|2, ..., SIZE (1|2|3))) -- cgit v1.2.3 From 4709d67f92bf89c264e38fbf94e3324edd922ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 23 Apr 2013 10:39:50 +0200 Subject: Fix encoding of semi-constrained, extensible INTEGERs Given: Semi ::= INTEGER (Lb..MAX, ...) where Lb is an arbitrary integer, attempting to encode an integer less than Lb would cause the encoder to enter an infinite loop. --- lib/asn1/test/testConstraints.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/asn1/test/testConstraints.erl') diff --git a/lib/asn1/test/testConstraints.erl b/lib/asn1/test/testConstraints.erl index b90ae8cab2..e825302629 100644 --- a/lib/asn1/test/testConstraints.erl +++ b/lib/asn1/test/testConstraints.erl @@ -131,6 +131,16 @@ int_constraints(Rules) -> roundtrip('NegSemiConstrained', -1), roundtrip('NegSemiConstrained', 500), + roundtrip('SemiConstrainedExt', -65536), + roundtrip('SemiConstrainedExt', 0), + roundtrip('SemiConstrainedExt', 42), + roundtrip('SemiConstrainedExt', 100), + roundtrip('SemiConstrainedExt', 47777789), + roundtrip('NegSemiConstrainedExt', -1023), + roundtrip('NegSemiConstrainedExt', -128), + roundtrip('NegSemiConstrainedExt', -1), + roundtrip('NegSemiConstrainedExt', 500), + %%========================================================== %% SIZE Constraint (Duboisson p. 268) %% T ::= IA5String (SIZE (1|2, ..., SIZE (1|2|3))) -- cgit v1.2.3