From 2f536be315d466458defbd98bf8f6f6c7969c2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 24 Oct 2023 08:04:54 +0200 Subject: [PATCH] wip --- lib/asn1/src/asn1ct_partial_decode.erl | 9 +++--- lib/asn1/src/asn1rtt_ber.erl | 44 +++++++++++++------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/lib/asn1/src/asn1ct_partial_decode.erl b/lib/asn1/src/asn1ct_partial_decode.erl index e3a8981b62b6..a587ac1a3565 100644 --- a/lib/asn1/src/asn1ct_partial_decode.erl +++ b/lib/asn1/src/asn1ct_partial_decode.erl @@ -333,15 +333,14 @@ get_tag_command(#type{}, ?SKIP) -> ?SKIP; get_tag_command(#type{tag=Tags}, ?SKIP_OPTIONAL) -> Tag = hd(Tags), - [?SKIP_OPTIONAL, + {?SKIP_OPTIONAL, ?ASN1CT_GEN_BER:encode_tag_val(?ASN1CT_GEN_BER:decode_class(Tag#tag.class), - Tag#tag.form, Tag#tag.number)]; + Tag#tag.form, Tag#tag.number)}; get_tag_command(#type{tag=[Tag]}, Command) -> - %% encode the tag according to BER - [Command, + {Command, ?ASN1CT_GEN_BER:encode_tag_val(?ASN1CT_GEN_BER:decode_class(Tag#tag.class), Tag#tag.form, - Tag#tag.number)]; + Tag#tag.number)}; get_tag_command(T=#type{tag=[Tag|Tags]},Command) -> TC = get_tag_command(T#type{tag=[Tag]}, Command), TCs = get_tag_command(T#type{tag=Tags}, Command), diff --git a/lib/asn1/src/asn1rtt_ber.erl b/lib/asn1/src/asn1rtt_ber.erl index e160f7eec3db..226a303100cc 100644 --- a/lib/asn1/src/asn1rtt_ber.erl +++ b/lib/asn1/src/asn1rtt_ber.erl @@ -352,35 +352,35 @@ incomplete_choice_alt(_,[]) -> %% Returns {ok,Value} or {error,Reason} %% Value is a binary that in turn must be decoded to get the decoded %% value. -decode_selective([],Binary) -> +decode_selective([], Binary) -> {ok,Binary}; -decode_selective([skip|RestPattern],Binary)-> - {ok,RestBinary}=skip_tag(Binary), - {ok,RestBinary2}=skip_length_and_value(RestBinary), - decode_selective(RestPattern,RestBinary2); -decode_selective([[skip_optional,Tag]|RestPattern],Binary) -> - case skip_optional_tag(Tag,Binary) of - {ok,RestBinary} -> - {ok,RestBinary2}=skip_length_and_value(RestBinary), - decode_selective(RestPattern,RestBinary2); - missing -> - decode_selective(RestPattern,Binary) +decode_selective([skip|RestPattern], Binary)-> + {ok,RestBinary} = skip_tag(Binary), + {ok,RestBinary2} = skip_length_and_value(RestBinary), + decode_selective(RestPattern, RestBinary2); +decode_selective([{skip_optional,Tag}|RestPattern], Binary) -> + case skip_optional_tag(Tag, Binary) of + {ok,RestBinary} -> + {ok,RestBinary2} = skip_length_and_value(RestBinary), + decode_selective(RestPattern, RestBinary2); + missing -> + decode_selective(RestPattern, Binary) end; -decode_selective([[chosen,Tag]],Binary) -> - return_value(Tag,Binary); -decode_selective([[chosen,Tag]|RestPattern],Binary) -> - case skip_optional_tag(Tag,Binary) of - {ok,RestBinary} -> - {ok,Value} = get_value(RestBinary), - decode_selective(RestPattern,Value); - missing -> - {ok,<<>>} +decode_selective([{chosen,Tag}], Binary) -> + return_value(Tag, Binary); +decode_selective([{chosen,Tag}|RestPattern], Binary) -> + case skip_optional_tag(Tag, Binary) of + {ok,RestBinary} -> + {ok,Value} = get_value(RestBinary), + decode_selective(RestPattern,Value); + missing -> + {ok,<<>>} end; decode_selective(P,_) -> {error,{asn1,{partial_decode,"bad pattern",P}}}. return_value(Tag,Binary) -> - {ok,{Tag,RestBinary}}=get_tag(Binary), + {ok,{Tag,RestBinary}} = get_tag(Binary), {ok,{LenVal,_RestBinary2}} = get_length_and_value(RestBinary), {ok,<>}.