diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl index 213e4f5b829d..7ee834f37ed8 100644 --- a/lib/asn1/src/asn1ct_gen.erl +++ b/lib/asn1/src/asn1ct_gen.erl @@ -941,7 +941,7 @@ 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,_} -> @@ -949,16 +949,25 @@ gen_decode_partial_incomplete(#gen{erule=ber}, NoOkWrapper) -> {_,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]), diff --git a/lib/asn1/test/Makefile b/lib/asn1/test/Makefile index 84f327ce45d2..a7e17a9e0acd 100644 --- a/lib/asn1/test/Makefile +++ b/lib/asn1/test/Makefile @@ -102,6 +102,7 @@ MODULES= \ testDER \ test_selective_decode \ test_special_decode_performance \ + test_exclusive_decode_rest \ testTCAP \ testSSLspecs \ testSelectionTypes \ diff --git a/lib/asn1/test/asn1_SUITE.erl b/lib/asn1/test/asn1_SUITE.erl index 11aa10eff945..c7889129f0ca 100644 --- a/lib/asn1/test/asn1_SUITE.erl +++ b/lib/asn1/test/asn1_SUITE.erl @@ -59,6 +59,7 @@ all() -> test_undecoded_rest, specialized_decodes, special_decode_performance, + exclusive_decode_rest, testMegaco, testConstraints, @@ -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]). diff --git a/lib/asn1/test/asn1_SUITE_data/SwCDR.asn1config b/lib/asn1/test/asn1_SUITE_data/SwCDR.asn1config new file mode 100644 index 000000000000..a2c96c43e98c --- /dev/null +++ b/lib/asn1/test/asn1_SUITE_data/SwCDR.asn1config @@ -0,0 +1,6 @@ +{exclusive_decode, + {'SwCDR', + [{decode_cdr, + ['SwCDR', + [{origSvcCallRecord, undecoded}, + {termSvcCallRecord, undecoded}]]}]}}. diff --git a/lib/asn1/test/test_exclusive_decode_rest.erl b/lib/asn1/test/test_exclusive_decode_rest.erl new file mode 100644 index 000000000000..2e17643369ce --- /dev/null +++ b/lib/asn1/test/test_exclusive_decode_rest.erl @@ -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 = <>, + {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}. +