From 5588449531f1a41d05e5d2d4fe5976db643a18e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 12 Mar 2013 08:35:48 +0100 Subject: PER: Ensure that the complete encoding is at least one byte If the encoding is empty (i.e. if a top-level type is single-valued and therefore not encoding), the result should be a single zero byte. --- lib/asn1/src/asn1rtt_per.erl | 5 ++++- lib/asn1/src/asn1rtt_uper.erl | 7 +++++-- lib/asn1/test/testPrim.erl | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/asn1/src/asn1rtt_per.erl b/lib/asn1/src/asn1rtt_per.erl index 84ff809912..aa6cf4da0a 100644 --- a/lib/asn1/src/asn1rtt_per.erl +++ b/lib/asn1/src/asn1rtt_per.erl @@ -963,7 +963,10 @@ encode_relative_oid(Val) when is_list(Val) -> %% complete(L) -> - asn1rt_nif:encode_per_complete(L). + case asn1rt_nif:encode_per_complete(L) of + <<>> -> <<0>>; + Bin -> Bin + end. octets_to_complete(Len,Val) when Len < 256 -> [20,Len,Val]; diff --git a/lib/asn1/src/asn1rtt_uper.erl b/lib/asn1/src/asn1rtt_uper.erl index ad0678f3c3..8efe9a7b0f 100644 --- a/lib/asn1/src/asn1rtt_uper.erl +++ b/lib/asn1/src/asn1rtt_uper.erl @@ -1016,8 +1016,11 @@ complete(InList) when is_list(InList) -> Bits -> <> end end; -complete(InList) when is_binary(InList) -> - InList; +complete(Bin) when is_binary(Bin) -> + case Bin of + <<>> -> <<0>>; + _ -> Bin + end; complete(InList) when is_bitstring(InList) -> PadLen = 8 - (bit_size(InList) band 7), <>. diff --git a/lib/asn1/test/testPrim.erl b/lib/asn1/test/testPrim.erl index 0d4427ba69..91fb9fffca 100644 --- a/lib/asn1/test/testPrim.erl +++ b/lib/asn1/test/testPrim.erl @@ -513,6 +513,14 @@ enum(Rules) -> case catch asn1_wrapper:encode('Prim','Enum',4) of Enum -> Enum end, ok end, + + case Rules of + Per when Per =:= per; Per =:= uper -> + {ok,<<0>>} = 'Prim':encode('SingleEnumVal', true), + {ok,<<0>>} = 'Prim':encode('SingleEnumValExt', true); + ber -> + ok + end, ok. -- cgit v1.2.3