Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Oct 24, 2023
1 parent f6c5503 commit 78ac7fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
58 changes: 30 additions & 28 deletions lib/asn1/src/asn1ct_partial_decode.erl
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ anonymous_dec_command(Command,_) ->
%%% Selective decode.
%%%

-define(CHOSEN, choosen).
-define(CHOSEN, chosen).
-define(SKIP, skip).
-define(SKIP_OPTIONAL, skip_optional).

%% Creates a list of tags out of the information in TypeList and Types
%% that tells which value will be decoded. Each constructed type that
%% is in the TypeList will get a "choosen" command. Only the last
%% is in the TypeList will get a "chosen" command. Only the last
%% type/component in the TypeList may be a primitive type. Components
%% "on the way" to the final element may get the "skip" or the
%% "skip_optional" command.
Expand Down Expand Up @@ -304,20 +304,20 @@ create_pdec_command(ModName,#'Externaltypereference'{module=M,type=C1},
create_pdec_command(ModName,TS=#type{def=Def},[C1|Cs],Acc) ->
%% This case when we got the "components" of a SEQUENCE/SET OF
case C1 of
[1] ->
%% A list with an integer is the only valid option in a 'S
%% OF', the other valid option would be an empty
%% TypeNameList saying that the entire 'S OF' will be
%% decoded.
TagCommand = get_tag_command(TS,?CHOSEN),
create_pdec_command(ModName,Def,Cs,concat_tags(TagCommand,Acc));
[N] when is_integer(N) ->
TagCommand = get_tag_command(TS,?SKIP),
create_pdec_command(ModName,Def,[[N-1]|Cs],
concat_tags(TagCommand,Acc));
Err ->
throw({error,{"unexpected error when creating partial "
"decode command",Err}})
[1] ->
%% A list with an integer is the only valid option in a 'S
%% OF', the other valid option would be an empty
%% TypeNameList saying that the entire 'S OF' will be
%% decoded.
TagCommand = get_tag_command(TS, ?CHOSEN),
create_pdec_command(ModName, Def, Cs, concat_tags(TagCommand,Acc));
[N] when is_integer(N) ->
TagCommand = get_tag_command(TS, ?SKIP),
create_pdec_command(ModName, Def, [[N-1]|Cs],
concat_tags(TagCommand,Acc));
Err ->
throw({error,{"unexpected error when creating partial "
"decode command",Err}})
end;
create_pdec_command(_,_,TNL,_) ->
throw({error,{"unexpected error when creating partial "
Expand All @@ -326,28 +326,30 @@ create_pdec_command(_,_,TNL,_) ->
%% Type is the type that has information about the tag Command tells
%% what to do with the encoded value with the tag of Type when
%% decoding.
get_tag_command(#type{tag=[]},_) ->
get_tag_command(#type{tag=[]}, _) ->
[];
%% SKIP and SKIP_OPTIONAL shall return only one tag command regardless.
get_tag_command(#type{},?SKIP) ->
get_tag_command(#type{}, ?SKIP) ->
?SKIP;
get_tag_command(#type{tag=Tags},?SKIP_OPTIONAL) ->
Tag=hd(Tags),
get_tag_command(#type{tag=Tags}, ?SKIP_OPTIONAL) ->
Tag = hd(Tags),
[?SKIP_OPTIONAL,
?ASN1CT_GEN_BER:encode_tag_val(?ASN1CT_GEN_BER:decode_class(Tag#tag.class),
Tag#tag.form,Tag#tag.number)];
get_tag_command(#type{tag=[Tag]},Command) ->
Tag#tag.form, Tag#tag.number)];
get_tag_command(#type{tag=[Tag]}, Command) ->
%% encode the tag according to BER
[Command,
?ASN1CT_GEN_BER:encode_tag_val(?ASN1CT_GEN_BER:decode_class(Tag#tag.class),Tag#tag.form,
?ASN1CT_GEN_BER:encode_tag_val(?ASN1CT_GEN_BER:decode_class(Tag#tag.class),
Tag#tag.form,
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),
TC = get_tag_command(T#type{tag=[Tag]}, Command),
TCs = get_tag_command(T#type{tag=Tags}, Command),
case many_tags(TCs) of
true when is_list(TCs) ->
[TC|TCs];
_ -> [TC|[TCs]]
true when is_list(TCs) ->
[TC|TCs];
_ ->
[TC|[TCs]]
end.

many_tags([?SKIP]) ->
Expand Down
4 changes: 2 additions & 2 deletions lib/asn1/src/asn1rtt_ber.erl
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ decode_selective([[skip_optional,Tag]|RestPattern],Binary) ->
missing ->
decode_selective(RestPattern,Binary)
end;
decode_selective([[choosen,Tag]],Binary) ->
decode_selective([[chosen,Tag]],Binary) ->
return_value(Tag,Binary);
decode_selective([[choosen,Tag]|RestPattern],Binary) ->
decode_selective([[chosen,Tag]|RestPattern],Binary) ->
case skip_optional_tag(Tag,Binary) of
{ok,RestBinary} ->
{ok,Value} = get_value(RestBinary),
Expand Down

0 comments on commit 78ac7fd

Please sign in to comment.