Skip to content

Commit

Permalink
Merge pull request #8798 from vances/asn1-undec_rest-asn1config
Browse files Browse the repository at this point in the history
asn1: Fix feature interaction with +undec_rest and +asn1config

OTP-19290
  • Loading branch information
bjorng authored Oct 9, 2024
2 parents 53e021d + 85c2317 commit 1252f99
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/asn1/src/asn1ct_gen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -941,24 +941,33 @@ gen_info_functions(Gen) ->
"legacy_erlang_types() -> ",
{asis,asn1ct:use_legacy_types()},".",nl,nl]).

gen_decode_partial_incomplete(#gen{erule=ber}, NoOkWrapper) ->
gen_decode_partial_incomplete(#gen{erule=ber, options=Options}, NoOkWrapper) ->
case {asn1ct:read_config_data(partial_incomplete_decode),
asn1ct:get_gen_state_field(inc_type_pattern)} of
{undefined,_} ->
ok;
{_,undefined} ->
ok;
_ ->
emit(["decode_partial_incomplete(Type, Data0, Pattern) ->",nl,
" {Data,_RestBin} =",nl,
" ",{call,ber,decode_primitive_incomplete,
["Pattern","Data0"]},com,nl]),
case NoOkWrapper of
true ->
emit([" decode_partial_inc_disp(Type, Data)",nl]);
false ->
emit([" try {ok,decode_partial_inc_disp(Type, Data)}",nl,
try_catch()])
emit(["decode_partial_incomplete(Type, Data0, Pattern) ->",nl]),
case {NoOkWrapper, lists:member(undec_rest, Options)} of
{true, _} ->
emit([" {Data,_RestBin} =",nl,
" ",{call,ber,decode_primitive_incomplete,
["Pattern","Data0"]},com,nl,
" decode_partial_inc_disp(Type, Data)",nl]);
{false, true} ->
emit([" {Data,RestBin} =",nl,
" ",{call,ber,decode_primitive_incomplete,
["Pattern","Data0"]},com,nl,
" try {ok,decode_partial_inc_disp(Type, Data),RestBin}",
nl,try_catch()]);
{false, false} ->
emit([" {Data,RestBin} =",nl,
" ",{call,ber,decode_primitive_incomplete,
["Pattern","Data0"]},com,nl,
" try {ok,decode_partial_inc_disp(Type, Data)}",
nl,try_catch()])
end,
emit([".",nl,nl]),

Expand Down
1 change: 1 addition & 0 deletions lib/asn1/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ MODULES= \
testDER \
test_selective_decode \
test_special_decode_performance \
test_exclusive_decode_rest \
testTCAP \
testSSLspecs \
testSelectionTypes \
Expand Down
8 changes: 8 additions & 0 deletions lib/asn1/test/asn1_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ all() ->
test_undecoded_rest,
specialized_decodes,
special_decode_performance,
exclusive_decode_rest,

testMegaco,
testConstraints,
Expand Down Expand Up @@ -967,6 +968,13 @@ special_decode_performance(Config, Rule, Opts) ->
asn1_test_lib:compile_all(Files, Config, [Rule, asn1config|Opts]),
test_special_decode_performance:go(all).

exclusive_decode_rest(Config) ->
test(Config, fun exclusive_decode_rest/3, [ber]).
exclusive_decode_rest(Config, Rule, Opts) ->
asn1_test_lib:compile("SwCDR.py", Config,
[Rule, undec_rest, asn1config|Opts]),
test_exclusive_decode_rest:test().

test_ParamTypeInfObj(Config) ->
asn1_test_lib:compile("IN-CS-1-Datatypes", Config, [ber]).

Expand Down
6 changes: 6 additions & 0 deletions lib/asn1/test/asn1_SUITE_data/SwCDR.asn1config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{exclusive_decode,
{'SwCDR',
[{decode_cdr,
['SwCDR',
[{origSvcCallRecord, undecoded},
{termSvcCallRecord, undecoded}]]}]}}.
35 changes: 35 additions & 0 deletions lib/asn1/test/test_exclusive_decode_rest.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2003-2024. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
%%
-module(test_exclusive_decode_rest).
-export([test/0]).

test() ->
{ok, CDR} = 'SwCDR':encode('SwCDR', {origSvcCallRecord, orig_cdr()}),
Bin = <<CDR/binary, CDR/binary>>,
{ok, {origSvcCallRecord, _}, CDR} = 'SwCDR':decode_cdr(Bin).

orig_cdr() ->
{'OrigSvcCallRecord', 1, 2, 3, <<145,65,97,85,21,50,244>>,
<<145,65,97,85,85,118,248>>, <<145,65,97,85,85,118,248>>,
<<2,0,2,4,1,0,0,5>>, <<2,0,3,2,4,5>>, 35000, 0, 0, 0, 3600,
3600, 3600, 3600, 48, 48, 64, 64, 20, 20, 12, 12, 20, 20,
4, 4, 1, 1, 3600, 3600, asn1_NOVALUE}.

0 comments on commit 1252f99

Please sign in to comment.