%% Generated by the Erlang ASN.1 BER_V2-compiler version, utilizing bit-syntax:4.0 %% Purpose: encoder and decoder to the types in mod ACSE-1 -module('ACSE-1'). -compile(nowarn_unused_vars). -include("ACSE-1.hrl"). -asn1_info([{vsn,'4.0'}, {module,'ACSE-1'}, {options,[{i,"/Users/quax/erl"}, warnings,ber,errors, {cwd,"/Users/quax/erl"}, {outdir,"/Users/quax/erl"}, {i,"/Users/quax/erl/acse"}, {i,"/Users/quax/erl/csta"}, {i,"."}]}]). -export([encoding_rule/0,bit_string_format/0, legacy_erlang_types/0]). -export(['dialyzer-suppressions'/1]). -export([ 'enc_ACSE-apdu'/2, 'enc_AARQ-apdu'/2, 'enc_AARE-apdu'/2, 'enc_RLRQ-apdu'/2, 'enc_RLRE-apdu'/2, 'enc_ABRT-apdu'/2, 'enc_ABRT-diagnostic'/2, 'enc_ABRT-source'/2, 'enc_ACSE-requirements'/2, 'enc_Application-context-name-list'/2, 'enc_Application-context-name'/2, 'enc_AP-title'/2, 'enc_AE-qualifier'/2, 'enc_AP-title-form1'/2, 'enc_AE-qualifier-form1'/2, 'enc_AP-title-form2'/2, 'enc_AE-qualifier-form2'/2, 'enc_AE-title'/2, 'enc_AE-title-form1'/2, 'enc_AE-title-form2'/2, 'enc_AE-invocation-identifier'/2, 'enc_AP-invocation-identifier'/2, 'enc_Associate-result'/2, 'enc_Associate-source-diagnostic'/2, 'enc_Association-information'/2, 'enc_Authentication-value'/2, 'enc_Implementation-data'/2, 'enc_Mechanism-name'/2, 'enc_Release-request-reason'/2, 'enc_Release-response-reason'/2, 'enc_EXTERNAL'/2 ]). -export([ 'dec_ACSE-apdu'/2, 'dec_AARQ-apdu'/2, 'dec_AARE-apdu'/2, 'dec_RLRQ-apdu'/2, 'dec_RLRE-apdu'/2, 'dec_ABRT-apdu'/2, 'dec_ABRT-diagnostic'/2, 'dec_ABRT-source'/2, 'dec_ACSE-requirements'/2, 'dec_Application-context-name-list'/2, 'dec_Application-context-name'/2, 'dec_AP-title'/2, 'dec_AE-qualifier'/2, 'dec_AP-title-form1'/2, 'dec_AE-qualifier-form1'/2, 'dec_AP-title-form2'/2, 'dec_AE-qualifier-form2'/2, 'dec_AE-title'/2, 'dec_AE-title-form1'/2, 'dec_AE-title-form2'/2, 'dec_AE-invocation-identifier'/2, 'dec_AP-invocation-identifier'/2, 'dec_Associate-result'/2, 'dec_Associate-source-diagnostic'/2, 'dec_Association-information'/2, 'dec_Authentication-value'/2, 'dec_Implementation-data'/2, 'dec_Mechanism-name'/2, 'dec_Release-request-reason'/2, 'dec_Release-response-reason'/2, 'dec_EXTERNAL'/2 ]). -export([ 'acse-as-id'/0, 'aCSE-id'/0 ]). -export([ 'getenc_ObjectSet'/1 ]). -export([ 'getdec_ObjectSet'/1 ]). -export([info/0]). -export([encode/2,decode/2]). encoding_rule() -> ber. bit_string_format() -> bitstring. legacy_erlang_types() -> false. encode(Type, Data) -> try iolist_to_binary(element(1, encode_disp(Type, Data))) of Bytes -> {ok,Bytes} catch Class:Exception when Class =:= error; Class =:= exit -> case Exception of {error,Reason}=Error -> Error; Reason -> {error,{asn1,Reason}} end end. decode(Type,Data) -> try decode_disp(Type, element(1, ber_decode_nif(Data))) of Result -> {ok,Result} catch Class:Exception when Class =:= error; Class =:= exit -> case Exception of {error,Reason}=Error -> Error; Reason -> {error,{asn1,Reason}} end end. encode_disp('ACSE-apdu',Data) -> 'enc_ACSE-apdu'(Data); encode_disp('AARQ-apdu',Data) -> 'enc_AARQ-apdu'(Data); encode_disp('AARE-apdu',Data) -> 'enc_AARE-apdu'(Data); encode_disp('RLRQ-apdu',Data) -> 'enc_RLRQ-apdu'(Data); encode_disp('RLRE-apdu',Data) -> 'enc_RLRE-apdu'(Data); encode_disp('ABRT-apdu',Data) -> 'enc_ABRT-apdu'(Data); encode_disp('ABRT-diagnostic',Data) -> 'enc_ABRT-diagnostic'(Data); encode_disp('ABRT-source',Data) -> 'enc_ABRT-source'(Data); encode_disp('ACSE-requirements',Data) -> 'enc_ACSE-requirements'(Data); encode_disp('Application-context-name-list',Data) -> 'enc_Application-context-name-list'(Data); encode_disp('Application-context-name',Data) -> 'enc_Application-context-name'(Data); encode_disp('AP-title',Data) -> 'enc_AP-title'(Data); encode_disp('AE-qualifier',Data) -> 'enc_AE-qualifier'(Data); encode_disp('AP-title-form1',Data) -> 'enc_AP-title-form1'(Data); encode_disp('AE-qualifier-form1',Data) -> 'enc_AE-qualifier-form1'(Data); encode_disp('AP-title-form2',Data) -> 'enc_AP-title-form2'(Data); encode_disp('AE-qualifier-form2',Data) -> 'enc_AE-qualifier-form2'(Data); encode_disp('AE-title',Data) -> 'enc_AE-title'(Data); encode_disp('AE-title-form1',Data) -> 'enc_AE-title-form1'(Data); encode_disp('AE-title-form2',Data) -> 'enc_AE-title-form2'(Data); encode_disp('AE-invocation-identifier',Data) -> 'enc_AE-invocation-identifier'(Data); encode_disp('AP-invocation-identifier',Data) -> 'enc_AP-invocation-identifier'(Data); encode_disp('Associate-result',Data) -> 'enc_Associate-result'(Data); encode_disp('Associate-source-diagnostic',Data) -> 'enc_Associate-source-diagnostic'(Data); encode_disp('Association-information',Data) -> 'enc_Association-information'(Data); encode_disp('Authentication-value',Data) -> 'enc_Authentication-value'(Data); encode_disp('Implementation-data',Data) -> 'enc_Implementation-data'(Data); encode_disp('Mechanism-name',Data) -> 'enc_Mechanism-name'(Data); encode_disp('Release-request-reason',Data) -> 'enc_Release-request-reason'(Data); encode_disp('Release-response-reason',Data) -> 'enc_Release-response-reason'(Data); encode_disp('EXTERNAL',Data) -> 'enc_EXTERNAL'(Data); encode_disp(Type,_Data) -> exit({error,{asn1,{undefined_type,Type}}}). decode_disp('ACSE-apdu',Data) -> 'dec_ACSE-apdu'(Data); decode_disp('AARQ-apdu',Data) -> 'dec_AARQ-apdu'(Data); decode_disp('AARE-apdu',Data) -> 'dec_AARE-apdu'(Data); decode_disp('RLRQ-apdu',Data) -> 'dec_RLRQ-apdu'(Data); decode_disp('RLRE-apdu',Data) -> 'dec_RLRE-apdu'(Data); decode_disp('ABRT-apdu',Data) -> 'dec_ABRT-apdu'(Data); decode_disp('ABRT-diagnostic',Data) -> 'dec_ABRT-diagnostic'(Data); decode_disp('ABRT-source',Data) -> 'dec_ABRT-source'(Data); decode_disp('ACSE-requirements',Data) -> 'dec_ACSE-requirements'(Data); decode_disp('Application-context-name-list',Data) -> 'dec_Application-context-name-list'(Data); decode_disp('Application-context-name',Data) -> 'dec_Application-context-name'(Data); decode_disp('AP-title',Data) -> 'dec_AP-title'(Data); decode_disp('AE-qualifier',Data) -> 'dec_AE-qualifier'(Data); decode_disp('AP-title-form1',Data) -> 'dec_AP-title-form1'(Data); decode_disp('AE-qualifier-form1',Data) -> 'dec_AE-qualifier-form1'(Data); decode_disp('AP-title-form2',Data) -> 'dec_AP-title-form2'(Data); decode_disp('AE-qualifier-form2',Data) -> 'dec_AE-qualifier-form2'(Data); decode_disp('AE-title',Data) -> 'dec_AE-title'(Data); decode_disp('AE-title-form1',Data) -> 'dec_AE-title-form1'(Data); decode_disp('AE-title-form2',Data) -> 'dec_AE-title-form2'(Data); decode_disp('AE-invocation-identifier',Data) -> 'dec_AE-invocation-identifier'(Data); decode_disp('AP-invocation-identifier',Data) -> 'dec_AP-invocation-identifier'(Data); decode_disp('Associate-result',Data) -> 'dec_Associate-result'(Data); decode_disp('Associate-source-diagnostic',Data) -> 'dec_Associate-source-diagnostic'(Data); decode_disp('Association-information',Data) -> 'dec_Association-information'(Data); decode_disp('Authentication-value',Data) -> 'dec_Authentication-value'(Data); decode_disp('Implementation-data',Data) -> 'dec_Implementation-data'(Data); decode_disp('Mechanism-name',Data) -> 'dec_Mechanism-name'(Data); decode_disp('Release-request-reason',Data) -> 'dec_Release-request-reason'(Data); decode_disp('Release-response-reason',Data) -> 'dec_Release-response-reason'(Data); decode_disp('EXTERNAL',Data) -> 'dec_EXTERNAL'(Data); decode_disp(Type,_Data) -> exit({error,{asn1,{undefined_type,Type}}}). info() -> case ?MODULE:module_info(attributes) of Attributes when is_list(Attributes) -> case lists:keyfind(asn1_info, 1, Attributes) of {_,Info} when is_list(Info) -> Info; _ -> [] end; _ -> [] end. %%================================ %% ACSE-apdu %%================================ 'enc_ACSE-apdu'(Val) -> 'enc_ACSE-apdu'(Val, []). 'enc_ACSE-apdu'(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of aarq -> 'enc_AARQ-apdu'(element(2,Val), [<<96>>]); aare -> 'enc_AARE-apdu'(element(2,Val), [<<97>>]); rlrq -> 'enc_RLRQ-apdu'(element(2,Val), [<<98>>]); rlre -> 'enc_RLRE-apdu'(element(2,Val), [<<99>>]); abrt -> 'enc_ABRT-apdu'(element(2,Val), [<<100>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). 'dec_ACSE-apdu'(Tlv) -> 'dec_ACSE-apdu'(Tlv, []). 'dec_ACSE-apdu'(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'aarq' {65536, V1} -> {aarq, 'dec_AARQ-apdu'(V1, [])}; %% 'aare' {65537, V1} -> {aare, 'dec_AARE-apdu'(V1, [])}; %% 'rlrq' {65538, V1} -> {rlrq, 'dec_RLRQ-apdu'(V1, [])}; %% 'rlre' {65539, V1} -> {rlre, 'dec_RLRE-apdu'(V1, [])}; %% 'abrt' {65540, V1} -> {abrt, 'dec_ABRT-apdu'(V1, [])}; Else -> {asn1_ExtAlt,ber_encode(Else)} end . %%================================ %% AARQ-apdu %%================================ 'enc_AARQ-apdu'(Val) -> 'enc_AARQ-apdu'(Val, [<<96>>]). 'enc_AARQ-apdu'(Val, TagIn) -> {_,Cindex1, Cindex2, Cindex3, Cindex4, Cindex5, Cindex6, Cindex7, Cindex8, Cindex9, Cindex10, Cindex11, Cindex12, Cindex13, Cindex14, Cindex15, Cindex16} = Val, %%------------------------------------------------- %% attribute protocol-version(1) with type BIT STRING DEFAULT = [version1] %%------------------------------------------------- {EncBytes1,EncLen1} = case Cindex1 of asn1_DEFAULT -> {<<>>,0}; [version1] -> {<<>>,0}; _ -> encode_named_bit_string(Cindex1, [{version1,0}], [<<128>>]) end, %%------------------------------------------------- %% attribute application-context-name(2) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes2,EncLen2} = encode_object_identifier(Cindex2, [<<6>>,<<161>>]), %%------------------------------------------------- %% attribute called-AP-title(3) External ACSE-1:AP-title OPTIONAL %%------------------------------------------------- {EncBytes3,EncLen3} = case Cindex3 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_AP-title'(Cindex3, [<<162>>]) end, %%------------------------------------------------- %% attribute called-AE-qualifier(4) External ACSE-1:AE-qualifier OPTIONAL %%------------------------------------------------- {EncBytes4,EncLen4} = case Cindex4 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_AE-qualifier'(Cindex4, [<<163>>]) end, %%------------------------------------------------- %% attribute called-AP-invocation-identifier(5) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes5,EncLen5} = case Cindex5 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex5, [<<2>>,<<164>>]) end, %%------------------------------------------------- %% attribute called-AE-invocation-identifier(6) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes6,EncLen6} = case Cindex6 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex6, [<<2>>,<<165>>]) end, %%------------------------------------------------- %% attribute calling-AP-title(7) External ACSE-1:AP-title OPTIONAL %%------------------------------------------------- {EncBytes7,EncLen7} = case Cindex7 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_AP-title'(Cindex7, [<<166>>]) end, %%------------------------------------------------- %% attribute calling-AE-qualifier(8) External ACSE-1:AE-qualifier OPTIONAL %%------------------------------------------------- {EncBytes8,EncLen8} = case Cindex8 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_AE-qualifier'(Cindex8, [<<167>>]) end, %%------------------------------------------------- %% attribute calling-AP-invocation-identifier(9) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes9,EncLen9} = case Cindex9 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex9, [<<2>>,<<168>>]) end, %%------------------------------------------------- %% attribute calling-AE-invocation-identifier(10) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes10,EncLen10} = case Cindex10 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex10, [<<2>>,<<169>>]) end, %%------------------------------------------------- %% attribute sender-acse-requirements(11) with type BIT STRING OPTIONAL %%------------------------------------------------- {EncBytes11,EncLen11} = case Cindex11 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_named_bit_string(Cindex11, [{authentication,0},{'application-context-negotiation',1}], [<<138>>]) end, %%------------------------------------------------- %% attribute mechanism-name(12) with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {EncBytes12,EncLen12} = case Cindex12 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_object_identifier(Cindex12, [<<139>>]) end, %%------------------------------------------------- %% attribute calling-authentication-value(13) External ACSE-1:Authentication-value OPTIONAL %%------------------------------------------------- {EncBytes13,EncLen13} = case Cindex13 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Authentication-value'(Cindex13, [<<172>>]) end, %%------------------------------------------------- %% attribute application-context-name-list(14) External ACSE-1:Application-context-name-list OPTIONAL %%------------------------------------------------- {EncBytes14,EncLen14} = case Cindex14 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Application-context-name-list'(Cindex14, [<<173>>]) end, %%------------------------------------------------- %% attribute implementation-information(15) with type GraphicString OPTIONAL %%------------------------------------------------- {EncBytes15,EncLen15} = case Cindex15 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_restricted_string(Cindex15, [<<157>>]) end, %%------------------------------------------------- %% attribute user-information(16) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {EncBytes16,EncLen16} = case Cindex16 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Association-information'(Cindex16, [<<190>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5, EncBytes6, EncBytes7, EncBytes8, EncBytes9, EncBytes10, EncBytes11, EncBytes12, EncBytes13, EncBytes14, EncBytes15, EncBytes16], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5 + EncLen6 + EncLen7 + EncLen8 + EncLen9 + EncLen10 + EncLen11 + EncLen12 + EncLen13 + EncLen14 + EncLen15 + EncLen16, encode_tags(TagIn, BytesSoFar, LenSoFar). 'dec_AARQ-apdu'(Tlv) -> 'dec_AARQ-apdu'(Tlv, [65536]). 'dec_AARQ-apdu'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute protocol-version(1) with type BIT STRING DEFAULT = [version1] %%------------------------------------------------- {Term1,Tlv2} = case Tlv1 of [{131072,V1}|TempTlv2] -> {decode_named_bit_string(V1, [{version1,0}], []), TempTlv2}; _ -> {[version1],Tlv1} end, %%------------------------------------------------- %% attribute application-context-name(2) with type OBJECT IDENTIFIER %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_object_identifier(V2, [131073,6]), %%------------------------------------------------- %% attribute called-AP-title(3) External ACSE-1:AP-title OPTIONAL %%------------------------------------------------- {Term3,Tlv4} = case Tlv3 of [{131074,V3}|TempTlv4] -> {'dec_AP-title'(V3, []), TempTlv4}; _ -> { asn1_NOVALUE, Tlv3} end, %%------------------------------------------------- %% attribute called-AE-qualifier(4) External ACSE-1:AE-qualifier OPTIONAL %%------------------------------------------------- {Term4,Tlv5} = case Tlv4 of [{131075,V4}|TempTlv5] -> {'dec_AE-qualifier'(V4, []), TempTlv5}; _ -> { asn1_NOVALUE, Tlv4} end, %%------------------------------------------------- %% attribute called-AP-invocation-identifier(5) with type INTEGER OPTIONAL %%------------------------------------------------- {Term5,Tlv6} = case Tlv5 of [{131076,V5}|TempTlv6] -> {decode_integer(V5, [2]), TempTlv6}; _ -> { asn1_NOVALUE, Tlv5} end, %%------------------------------------------------- %% attribute called-AE-invocation-identifier(6) with type INTEGER OPTIONAL %%------------------------------------------------- {Term6,Tlv7} = case Tlv6 of [{131077,V6}|TempTlv7] -> {decode_integer(V6, [2]), TempTlv7}; _ -> { asn1_NOVALUE, Tlv6} end, %%------------------------------------------------- %% attribute calling-AP-title(7) External ACSE-1:AP-title OPTIONAL %%------------------------------------------------- {Term7,Tlv8} = case Tlv7 of [{131078,V7}|TempTlv8] -> {'dec_AP-title'(V7, []), TempTlv8}; _ -> { asn1_NOVALUE, Tlv7} end, %%------------------------------------------------- %% attribute calling-AE-qualifier(8) External ACSE-1:AE-qualifier OPTIONAL %%------------------------------------------------- {Term8,Tlv9} = case Tlv8 of [{131079,V8}|TempTlv9] -> {'dec_AE-qualifier'(V8, []), TempTlv9}; _ -> { asn1_NOVALUE, Tlv8} end, %%------------------------------------------------- %% attribute calling-AP-invocation-identifier(9) with type INTEGER OPTIONAL %%------------------------------------------------- {Term9,Tlv10} = case Tlv9 of [{131080,V9}|TempTlv10] -> {decode_integer(V9, [2]), TempTlv10}; _ -> { asn1_NOVALUE, Tlv9} end, %%------------------------------------------------- %% attribute calling-AE-invocation-identifier(10) with type INTEGER OPTIONAL %%------------------------------------------------- {Term10,Tlv11} = case Tlv10 of [{131081,V10}|TempTlv11] -> {decode_integer(V10, [2]), TempTlv11}; _ -> { asn1_NOVALUE, Tlv10} end, %%------------------------------------------------- %% attribute sender-acse-requirements(11) with type BIT STRING OPTIONAL %%------------------------------------------------- {Term11,Tlv12} = case Tlv11 of [{131082,V11}|TempTlv12] -> {decode_named_bit_string(V11, [{authentication,0},{'application-context-negotiation',1}], []), TempTlv12}; _ -> { asn1_NOVALUE, Tlv11} end, %%------------------------------------------------- %% attribute mechanism-name(12) with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {Term12,Tlv13} = case Tlv12 of [{131083,V12}|TempTlv13] -> {decode_object_identifier(V12, []), TempTlv13}; _ -> { asn1_NOVALUE, Tlv12} end, %%------------------------------------------------- %% attribute calling-authentication-value(13) External ACSE-1:Authentication-value OPTIONAL %%------------------------------------------------- {Term13,Tlv14} = case Tlv13 of [{131084,V13}|TempTlv14] -> {'dec_Authentication-value'(V13, []), TempTlv14}; _ -> { asn1_NOVALUE, Tlv13} end, %%------------------------------------------------- %% attribute application-context-name-list(14) External ACSE-1:Application-context-name-list OPTIONAL %%------------------------------------------------- {Term14,Tlv15} = case Tlv14 of [{131085,V14}|TempTlv15] -> {'dec_Application-context-name-list'(V14, []), TempTlv15}; _ -> { asn1_NOVALUE, Tlv14} end, %%------------------------------------------------- %% attribute implementation-information(15) with type GraphicString OPTIONAL %%------------------------------------------------- {Term15,Tlv16} = case Tlv15 of [{131101,V15}|TempTlv16] -> {begin binary_to_list(decode_restricted_string(V15, [])) end , TempTlv16}; _ -> { asn1_NOVALUE, Tlv15} end, Tlv17 = skip_ExtensionAdditions(Tlv16, [131102]), %%------------------------------------------------- %% attribute user-information(15) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {Term16,Tlv18} = case Tlv17 of [{131102,V16}|TempTlv18] -> {'dec_Association-information'(V16, []), TempTlv18}; _ -> { asn1_NOVALUE, Tlv17} end, case Tlv18 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv18}}}) % extra fields not allowed end, {'AARQ-apdu', Term1, Term2, Term3, Term4, Term5, Term6, Term7, Term8, Term9, Term10, Term11, Term12, Term13, Term14, Term15, Term16}. %%================================ %% AARE-apdu %%================================ 'enc_AARE-apdu'(Val) -> 'enc_AARE-apdu'(Val, [<<97>>]). 'enc_AARE-apdu'(Val, TagIn) -> {_,Cindex1, Cindex2, Cindex3, Cindex4, Cindex5, Cindex6, Cindex7, Cindex8, Cindex9, Cindex10, Cindex11, Cindex12, Cindex13, Cindex14} = Val, %%------------------------------------------------- %% attribute protocol-version(1) with type BIT STRING DEFAULT = [version1] %%------------------------------------------------- {EncBytes1,EncLen1} = case Cindex1 of asn1_DEFAULT -> {<<>>,0}; [version1] -> {<<>>,0}; _ -> encode_named_bit_string(Cindex1, [{version1,0}], [<<128>>]) end, %%------------------------------------------------- %% attribute application-context-name(2) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes2,EncLen2} = encode_object_identifier(Cindex2, [<<6>>,<<161>>]), %%------------------------------------------------- %% attribute result(3) with type INTEGER %%------------------------------------------------- {EncBytes3,EncLen3} = encode_integer(Cindex3, [{accepted,0},{'rejected-permanent',1},{'rejected-transient',2}], [<<2>>,<<162>>]), %%------------------------------------------------- %% attribute result-source-diagnostic(4) External ACSE-1:Associate-source-diagnostic %%------------------------------------------------- {EncBytes4,EncLen4} = 'enc_Associate-source-diagnostic'(Cindex4, [<<163>>]), %%------------------------------------------------- %% attribute responding-AP-title(5) External ACSE-1:AP-title OPTIONAL %%------------------------------------------------- {EncBytes5,EncLen5} = case Cindex5 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_AP-title'(Cindex5, [<<164>>]) end, %%------------------------------------------------- %% attribute responding-AE-qualifier(6) External ACSE-1:AE-qualifier OPTIONAL %%------------------------------------------------- {EncBytes6,EncLen6} = case Cindex6 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_AE-qualifier'(Cindex6, [<<165>>]) end, %%------------------------------------------------- %% attribute responding-AP-invocation-identifier(7) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes7,EncLen7} = case Cindex7 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex7, [<<2>>,<<166>>]) end, %%------------------------------------------------- %% attribute responding-AE-invocation-identifier(8) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes8,EncLen8} = case Cindex8 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex8, [<<2>>,<<167>>]) end, %%------------------------------------------------- %% attribute responder-acse-requirements(9) with type BIT STRING OPTIONAL %%------------------------------------------------- {EncBytes9,EncLen9} = case Cindex9 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_named_bit_string(Cindex9, [{authentication,0},{'application-context-negotiation',1}], [<<136>>]) end, %%------------------------------------------------- %% attribute mechanism-name(10) with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {EncBytes10,EncLen10} = case Cindex10 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_object_identifier(Cindex10, [<<137>>]) end, %%------------------------------------------------- %% attribute responding-authentication-value(11) External ACSE-1:Authentication-value OPTIONAL %%------------------------------------------------- {EncBytes11,EncLen11} = case Cindex11 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Authentication-value'(Cindex11, [<<170>>]) end, %%------------------------------------------------- %% attribute application-context-name-list(12) External ACSE-1:Application-context-name-list OPTIONAL %%------------------------------------------------- {EncBytes12,EncLen12} = case Cindex12 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Application-context-name-list'(Cindex12, [<<171>>]) end, %%------------------------------------------------- %% attribute implementation-information(13) with type GraphicString OPTIONAL %%------------------------------------------------- {EncBytes13,EncLen13} = case Cindex13 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_restricted_string(Cindex13, [<<157>>]) end, %%------------------------------------------------- %% attribute user-information(14) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {EncBytes14,EncLen14} = case Cindex14 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Association-information'(Cindex14, [<<190>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5, EncBytes6, EncBytes7, EncBytes8, EncBytes9, EncBytes10, EncBytes11, EncBytes12, EncBytes13, EncBytes14], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5 + EncLen6 + EncLen7 + EncLen8 + EncLen9 + EncLen10 + EncLen11 + EncLen12 + EncLen13 + EncLen14, encode_tags(TagIn, BytesSoFar, LenSoFar). 'dec_AARE-apdu'(Tlv) -> 'dec_AARE-apdu'(Tlv, [65537]). 'dec_AARE-apdu'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute protocol-version(1) with type BIT STRING DEFAULT = [version1] %%------------------------------------------------- {Term1,Tlv2} = case Tlv1 of [{131072,V1}|TempTlv2] -> {decode_named_bit_string(V1, [{version1,0}], []), TempTlv2}; _ -> {[version1],Tlv1} end, %%------------------------------------------------- %% attribute application-context-name(2) with type OBJECT IDENTIFIER %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_object_identifier(V2, [131073,6]), %%------------------------------------------------- %% attribute result(3) with type INTEGER %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = begin Val1 = decode_integer(V3, [131074,2]), number2name(Val1, [{accepted,0},{'rejected-permanent',1},{'rejected-transient',2}]) end , %%------------------------------------------------- %% attribute result-source-diagnostic(4) External ACSE-1:Associate-source-diagnostic %%------------------------------------------------- [V4|Tlv5] = Tlv4, Term4 = 'dec_Associate-source-diagnostic'(V4, [131075]), %%------------------------------------------------- %% attribute responding-AP-title(5) External ACSE-1:AP-title OPTIONAL %%------------------------------------------------- {Term5,Tlv6} = case Tlv5 of [{131076,V5}|TempTlv6] -> {'dec_AP-title'(V5, []), TempTlv6}; _ -> { asn1_NOVALUE, Tlv5} end, %%------------------------------------------------- %% attribute responding-AE-qualifier(6) External ACSE-1:AE-qualifier OPTIONAL %%------------------------------------------------- {Term6,Tlv7} = case Tlv6 of [{131077,V6}|TempTlv7] -> {'dec_AE-qualifier'(V6, []), TempTlv7}; _ -> { asn1_NOVALUE, Tlv6} end, %%------------------------------------------------- %% attribute responding-AP-invocation-identifier(7) with type INTEGER OPTIONAL %%------------------------------------------------- {Term7,Tlv8} = case Tlv7 of [{131078,V7}|TempTlv8] -> {decode_integer(V7, [2]), TempTlv8}; _ -> { asn1_NOVALUE, Tlv7} end, %%------------------------------------------------- %% attribute responding-AE-invocation-identifier(8) with type INTEGER OPTIONAL %%------------------------------------------------- {Term8,Tlv9} = case Tlv8 of [{131079,V8}|TempTlv9] -> {decode_integer(V8, [2]), TempTlv9}; _ -> { asn1_NOVALUE, Tlv8} end, %%------------------------------------------------- %% attribute responder-acse-requirements(9) with type BIT STRING OPTIONAL %%------------------------------------------------- {Term9,Tlv10} = case Tlv9 of [{131080,V9}|TempTlv10] -> {decode_named_bit_string(V9, [{authentication,0},{'application-context-negotiation',1}], []), TempTlv10}; _ -> { asn1_NOVALUE, Tlv9} end, %%------------------------------------------------- %% attribute mechanism-name(10) with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {Term10,Tlv11} = case Tlv10 of [{131081,V10}|TempTlv11] -> {decode_object_identifier(V10, []), TempTlv11}; _ -> { asn1_NOVALUE, Tlv10} end, %%------------------------------------------------- %% attribute responding-authentication-value(11) External ACSE-1:Authentication-value OPTIONAL %%------------------------------------------------- {Term11,Tlv12} = case Tlv11 of [{131082,V11}|TempTlv12] -> {'dec_Authentication-value'(V11, []), TempTlv12}; _ -> { asn1_NOVALUE, Tlv11} end, %%------------------------------------------------- %% attribute application-context-name-list(12) External ACSE-1:Application-context-name-list OPTIONAL %%------------------------------------------------- {Term12,Tlv13} = case Tlv12 of [{131083,V12}|TempTlv13] -> {'dec_Application-context-name-list'(V12, []), TempTlv13}; _ -> { asn1_NOVALUE, Tlv12} end, %%------------------------------------------------- %% attribute implementation-information(13) with type GraphicString OPTIONAL %%------------------------------------------------- {Term13,Tlv14} = case Tlv13 of [{131101,V13}|TempTlv14] -> {begin binary_to_list(decode_restricted_string(V13, [])) end , TempTlv14}; _ -> { asn1_NOVALUE, Tlv13} end, Tlv15 = skip_ExtensionAdditions(Tlv14, [131102]), %%------------------------------------------------- %% attribute user-information(13) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {Term14,Tlv16} = case Tlv15 of [{131102,V14}|TempTlv16] -> {'dec_Association-information'(V14, []), TempTlv16}; _ -> { asn1_NOVALUE, Tlv15} end, case Tlv16 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv16}}}) % extra fields not allowed end, {'AARE-apdu', Term1, Term2, Term3, Term4, Term5, Term6, Term7, Term8, Term9, Term10, Term11, Term12, Term13, Term14}. %%================================ %% RLRQ-apdu %%================================ 'enc_RLRQ-apdu'(Val) -> 'enc_RLRQ-apdu'(Val, [<<98>>]). 'enc_RLRQ-apdu'(Val, TagIn) -> {_,Cindex1, Cindex2} = Val, %%------------------------------------------------- %% attribute reason(1) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes1,EncLen1} = case Cindex1 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex1, [{normal,0},{urgent,1},{'user-defined',30}], [<<128>>]) end, %%------------------------------------------------- %% attribute user-information(2) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Association-information'(Cindex2, [<<190>>]) end, BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). 'dec_RLRQ-apdu'(Tlv) -> 'dec_RLRQ-apdu'(Tlv, [65538]). 'dec_RLRQ-apdu'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute reason(1) with type INTEGER OPTIONAL %%------------------------------------------------- {Term1,Tlv2} = case Tlv1 of [{131072,V1}|TempTlv2] -> {begin Val1 = decode_integer(V1, []), number2name(Val1, [{normal,0},{urgent,1},{'user-defined',30}]) end , TempTlv2}; _ -> { asn1_NOVALUE, Tlv1} end, Tlv3 = skip_ExtensionAdditions(Tlv2, [131102]), %%------------------------------------------------- %% attribute user-information(1) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {Term2,Tlv4} = case Tlv3 of [{131102,V2}|TempTlv4] -> {'dec_Association-information'(V2, []), TempTlv4}; _ -> { asn1_NOVALUE, Tlv3} end, case Tlv4 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed end, {'RLRQ-apdu', Term1, Term2}. %%================================ %% RLRE-apdu %%================================ 'enc_RLRE-apdu'(Val) -> 'enc_RLRE-apdu'(Val, [<<99>>]). 'enc_RLRE-apdu'(Val, TagIn) -> {_,Cindex1, Cindex2} = Val, %%------------------------------------------------- %% attribute reason(1) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes1,EncLen1} = case Cindex1 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex1, [{normal,0},{'not-finished',1},{'user-defined',30}], [<<128>>]) end, %%------------------------------------------------- %% attribute user-information(2) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Association-information'(Cindex2, [<<190>>]) end, BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). 'dec_RLRE-apdu'(Tlv) -> 'dec_RLRE-apdu'(Tlv, [65539]). 'dec_RLRE-apdu'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute reason(1) with type INTEGER OPTIONAL %%------------------------------------------------- {Term1,Tlv2} = case Tlv1 of [{131072,V1}|TempTlv2] -> {begin Val1 = decode_integer(V1, []), number2name(Val1, [{normal,0},{'not-finished',1},{'user-defined',30}]) end , TempTlv2}; _ -> { asn1_NOVALUE, Tlv1} end, Tlv3 = skip_ExtensionAdditions(Tlv2, [131102]), %%------------------------------------------------- %% attribute user-information(1) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {Term2,Tlv4} = case Tlv3 of [{131102,V2}|TempTlv4] -> {'dec_Association-information'(V2, []), TempTlv4}; _ -> { asn1_NOVALUE, Tlv3} end, case Tlv4 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed end, {'RLRE-apdu', Term1, Term2}. %%================================ %% ABRT-apdu %%================================ 'enc_ABRT-apdu'(Val) -> 'enc_ABRT-apdu'(Val, [<<100>>]). 'enc_ABRT-apdu'(Val, TagIn) -> {_,Cindex1, Cindex2, Cindex3} = Val, %%------------------------------------------------- %% attribute abort-source(1) with type INTEGER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_integer(Cindex1, [{'acse-service-user',0},{'acse-service-provider',1}], [<<128>>]), %%------------------------------------------------- %% attribute abort-diagnostic(2) with type ENUMERATED OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> case Cindex2 of 'no-reason-given' -> encode_tags([<<129>>], [1], 1); 'protocol-error' -> encode_tags([<<129>>], [2], 1); 'authentication-mechanism-name-not-recognized' -> encode_tags([<<129>>], [3], 1); 'authentication-mechanism-name-required' -> encode_tags([<<129>>], [4], 1); 'authentication-failure' -> encode_tags([<<129>>], [5], 1); 'authentication-required' -> encode_tags([<<129>>], [6], 1); Enumval2 -> exit({error,{asn1, {enumerated_not_in_range,Enumval2}}}) end end, %%------------------------------------------------- %% attribute user-information(3) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {EncBytes3,EncLen3} = case Cindex3 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_Association-information'(Cindex3, [<<190>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3], LenSoFar = EncLen1 + EncLen2 + EncLen3, encode_tags(TagIn, BytesSoFar, LenSoFar). 'dec_ABRT-apdu'(Tlv) -> 'dec_ABRT-apdu'(Tlv, [65540]). 'dec_ABRT-apdu'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute abort-source(1) with type INTEGER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = begin Val1 = decode_integer(V1, [131072]), number2name(Val1, [{'acse-service-user',0},{'acse-service-provider',1}]) end , %%------------------------------------------------- %% attribute abort-diagnostic(2) with type ENUMERATED OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [{131073,V2}|TempTlv3] -> {case decode_integer(V2, []) of 1 -> 'no-reason-given'; 2 -> 'protocol-error'; 3 -> 'authentication-mechanism-name-not-recognized'; 4 -> 'authentication-mechanism-name-required'; 5 -> 'authentication-failure'; 6 -> 'authentication-required'; Default1 -> {asn1_enum,Default1} end, TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, Tlv4 = skip_ExtensionAdditions(Tlv3, [131102]), %%------------------------------------------------- %% attribute user-information(2) External ACSE-1:Association-information OPTIONAL %%------------------------------------------------- {Term3,Tlv5} = case Tlv4 of [{131102,V3}|TempTlv5] -> {'dec_Association-information'(V3, []), TempTlv5}; _ -> { asn1_NOVALUE, Tlv4} end, case Tlv5 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv5}}}) % extra fields not allowed end, {'ABRT-apdu', Term1, Term2, Term3}. %%================================ %% ABRT-diagnostic %%================================ 'enc_ABRT-diagnostic'(Val) -> 'enc_ABRT-diagnostic'(Val, [<<10>>]). 'enc_ABRT-diagnostic'(Val, TagIn) -> case Val of 'no-reason-given' -> encode_tags(TagIn, [1], 1); 'protocol-error' -> encode_tags(TagIn, [2], 1); 'authentication-mechanism-name-not-recognized' -> encode_tags(TagIn, [3], 1); 'authentication-mechanism-name-required' -> encode_tags(TagIn, [4], 1); 'authentication-failure' -> encode_tags(TagIn, [5], 1); 'authentication-required' -> encode_tags(TagIn, [6], 1); Enumval1 -> exit({error,{asn1, {enumerated_not_in_range,Enumval1}}}) end. 'dec_ABRT-diagnostic'(Tlv) -> 'dec_ABRT-diagnostic'(Tlv, [10]). 'dec_ABRT-diagnostic'(Tlv, TagIn) -> case decode_integer(Tlv, TagIn) of 1 -> 'no-reason-given'; 2 -> 'protocol-error'; 3 -> 'authentication-mechanism-name-not-recognized'; 4 -> 'authentication-mechanism-name-required'; 5 -> 'authentication-failure'; 6 -> 'authentication-required'; Default1 -> {asn1_enum,Default1} end. %%================================ %% ABRT-source %%================================ 'enc_ABRT-source'(Val) -> 'enc_ABRT-source'(Val, [<<2>>]). 'enc_ABRT-source'(Val, TagIn) -> encode_integer(Val, [{'acse-service-user',0},{'acse-service-provider',1}], TagIn). 'dec_ABRT-source'(Tlv) -> 'dec_ABRT-source'(Tlv, [2]). 'dec_ABRT-source'(Tlv, TagIn) -> begin Val1 = decode_integer(Tlv, TagIn), number2name(Val1, [{'acse-service-user',0},{'acse-service-provider',1}]) end . %%================================ %% ACSE-requirements %%================================ 'enc_ACSE-requirements'(Val) -> 'enc_ACSE-requirements'(Val, [<<3>>]). 'enc_ACSE-requirements'(Val, TagIn) -> encode_named_bit_string(Val, [{authentication,0},{'application-context-negotiation',1}], TagIn). 'dec_ACSE-requirements'(Tlv) -> 'dec_ACSE-requirements'(Tlv, [3]). 'dec_ACSE-requirements'(Tlv, TagIn) -> decode_named_bit_string(Tlv, [{authentication,0},{'application-context-negotiation',1}], TagIn). %%================================ %% Application-context-name-list %%================================ 'enc_Application-context-name-list'(Val) -> 'enc_Application-context-name-list'(Val, [<<48>>]). 'enc_Application-context-name-list'(Val, TagIn) -> {EncBytes,EncLen} = 'enc_Application-context-name-list_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_Application-context-name-list_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_Application-context-name-list_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = encode_object_identifier(H, [<<6>>]), 'enc_Application-context-name-list_components'(T,[EncBytes|AccBytes], AccLen + EncLen). 'dec_Application-context-name-list'(Tlv) -> 'dec_Application-context-name-list'(Tlv, [16]). 'dec_Application-context-name-list'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), [decode_object_identifier(V1, [6]) || V1 <- Tlv1]. %%================================ %% Application-context-name %%================================ 'enc_Application-context-name'(Val) -> 'enc_Application-context-name'(Val, [<<6>>]). 'enc_Application-context-name'(Val, TagIn) -> encode_object_identifier(Val, TagIn). 'dec_Application-context-name'(Tlv) -> 'dec_Application-context-name'(Tlv, [6]). 'dec_Application-context-name'(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% AP-title %%================================ 'enc_AP-title'(Val) -> 'enc_AP-title'(Val, []). 'enc_AP-title'(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of 'ap-title-form1' -> 'enc_AP-title-form1'(element(2,Val), []); 'ap-title-form2' -> encode_object_identifier(element(2,Val), [<<6>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). 'dec_AP-title'(Tlv) -> 'dec_AP-title'(Tlv, []). 'dec_AP-title'(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'ap-title-form1' V1 = {16,_} -> {'ap-title-form1', 'dec_AP-title-form1'(V1, [])}; %% 'ap-title-form2' {6, V1} -> {'ap-title-form2', decode_object_identifier(V1, [])}; Else -> {asn1_ExtAlt,ber_encode(Else)} end . %%================================ %% AE-qualifier %%================================ 'enc_AE-qualifier'(Val) -> 'enc_AE-qualifier'(Val, []). 'enc_AE-qualifier'(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of 'ae-qualifier-form1' -> 'enc_AE-qualifier-form1'(element(2,Val), [<<49>>]); 'ae-qualifier-form2' -> encode_integer(element(2,Val), [<<2>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). 'dec_AE-qualifier'(Tlv) -> 'dec_AE-qualifier'(Tlv, []). 'dec_AE-qualifier'(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'ae-qualifier-form1' {17, V1} -> {'ae-qualifier-form1', 'dec_AE-qualifier-form1'(V1, [])}; %% 'ae-qualifier-form2' {2, V1} -> {'ae-qualifier-form2', decode_integer(V1, [])}; Else -> {asn1_ExtAlt,ber_encode(Else)} end . %%================================ %% AP-title-form1 %%================================ 'enc_AP-title-form1'(Val) -> 'enc_AP-title-form1'(Val, []). 'enc_AP-title-form1'(Val, TagIn) -> 'InformationFramework':'enc_Name'(Val, TagIn). 'dec_AP-title-form1'(Tlv) -> 'dec_AP-title-form1'(Tlv, []). 'dec_AP-title-form1'(Tlv, TagIn) -> 'InformationFramework':'dec_Name'(Tlv, TagIn). %%================================ %% AE-qualifier-form1 %%================================ 'enc_AE-qualifier-form1'(Val) -> 'enc_AE-qualifier-form1'(Val, [<<49>>]). 'enc_AE-qualifier-form1'(Val, TagIn) -> 'InformationFramework':'enc_RelativeDistinguishedName'(Val, TagIn). 'dec_AE-qualifier-form1'(Tlv) -> 'dec_AE-qualifier-form1'(Tlv, [17]). 'dec_AE-qualifier-form1'(Tlv, TagIn) -> 'InformationFramework':'dec_RelativeDistinguishedName'(Tlv, TagIn). %%================================ %% AP-title-form2 %%================================ 'enc_AP-title-form2'(Val) -> 'enc_AP-title-form2'(Val, [<<6>>]). 'enc_AP-title-form2'(Val, TagIn) -> encode_object_identifier(Val, TagIn). 'dec_AP-title-form2'(Tlv) -> 'dec_AP-title-form2'(Tlv, [6]). 'dec_AP-title-form2'(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% AE-qualifier-form2 %%================================ 'enc_AE-qualifier-form2'(Val) -> 'enc_AE-qualifier-form2'(Val, [<<2>>]). 'enc_AE-qualifier-form2'(Val, TagIn) -> encode_integer(Val, TagIn). 'dec_AE-qualifier-form2'(Tlv) -> 'dec_AE-qualifier-form2'(Tlv, [2]). 'dec_AE-qualifier-form2'(Tlv, TagIn) -> decode_integer(Tlv, TagIn). %%================================ %% AE-title %%================================ 'enc_AE-title'(Val) -> 'enc_AE-title'(Val, []). 'enc_AE-title'(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of 'ae-title-form1' -> 'enc_AE-title-form1'(element(2,Val), []); 'ae-title-form2' -> encode_object_identifier(element(2,Val), [<<6>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). 'dec_AE-title'(Tlv) -> 'dec_AE-title'(Tlv, []). 'dec_AE-title'(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'ae-title-form1' V1 = {16,_} -> {'ae-title-form1', 'dec_AE-title-form1'(V1, [])}; %% 'ae-title-form2' {6, V1} -> {'ae-title-form2', decode_object_identifier(V1, [])}; Else -> {asn1_ExtAlt,ber_encode(Else)} end . %%================================ %% AE-title-form1 %%================================ 'enc_AE-title-form1'(Val) -> 'enc_AE-title-form1'(Val, []). 'enc_AE-title-form1'(Val, TagIn) -> 'InformationFramework':'enc_Name'(Val, TagIn). 'dec_AE-title-form1'(Tlv) -> 'dec_AE-title-form1'(Tlv, []). 'dec_AE-title-form1'(Tlv, TagIn) -> 'InformationFramework':'dec_Name'(Tlv, TagIn). %%================================ %% AE-title-form2 %%================================ 'enc_AE-title-form2'(Val) -> 'enc_AE-title-form2'(Val, [<<6>>]). 'enc_AE-title-form2'(Val, TagIn) -> encode_object_identifier(Val, TagIn). 'dec_AE-title-form2'(Tlv) -> 'dec_AE-title-form2'(Tlv, [6]). 'dec_AE-title-form2'(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% AE-invocation-identifier %%================================ 'enc_AE-invocation-identifier'(Val) -> 'enc_AE-invocation-identifier'(Val, [<<2>>]). 'enc_AE-invocation-identifier'(Val, TagIn) -> encode_integer(Val, TagIn). 'dec_AE-invocation-identifier'(Tlv) -> 'dec_AE-invocation-identifier'(Tlv, [2]). 'dec_AE-invocation-identifier'(Tlv, TagIn) -> decode_integer(Tlv, TagIn). %%================================ %% AP-invocation-identifier %%================================ 'enc_AP-invocation-identifier'(Val) -> 'enc_AP-invocation-identifier'(Val, [<<2>>]). 'enc_AP-invocation-identifier'(Val, TagIn) -> encode_integer(Val, TagIn). 'dec_AP-invocation-identifier'(Tlv) -> 'dec_AP-invocation-identifier'(Tlv, [2]). 'dec_AP-invocation-identifier'(Tlv, TagIn) -> decode_integer(Tlv, TagIn). %%================================ %% Associate-result %%================================ 'enc_Associate-result'(Val) -> 'enc_Associate-result'(Val, [<<2>>]). 'enc_Associate-result'(Val, TagIn) -> encode_integer(Val, [{accepted,0},{'rejected-permanent',1},{'rejected-transient',2}], TagIn). 'dec_Associate-result'(Tlv) -> 'dec_Associate-result'(Tlv, [2]). 'dec_Associate-result'(Tlv, TagIn) -> begin Val1 = decode_integer(Tlv, TagIn), number2name(Val1, [{accepted,0},{'rejected-permanent',1},{'rejected-transient',2}]) end . %%================================ %% Associate-source-diagnostic %%================================ 'enc_Associate-source-diagnostic'(Val) -> 'enc_Associate-source-diagnostic'(Val, []). 'enc_Associate-source-diagnostic'(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of 'acse-service-user' -> encode_integer(element(2,Val), [{null,0},{'no-reason-given',1},{'application-context-name-not-supported',2},{'calling-AP-title-not-recognized',3},{'calling-AP-invocation-identifier-not-recognized',4},{'calling-AE-qualifier-not-recognized',5},{'calling-AE-invocation-identifier-not-recognized',6},{'called-AP-title-not-recognized',7},{'called-AP-invocation-identifier-not-recognized',8},{'called-AE-qualifier-not-recognized',9},{'called-AE-invocation-identifier-not-recognized',10},{'authentication-mechanism-name-not-recognized',11},{'authentication-mechanism-name-required',12},{'authentication-failure',13},{'authentication-required',14}], [<<2>>,<<161>>]); 'acse-service-provider' -> encode_integer(element(2,Val), [{null,0},{'no-reason-given',1},{'no-common-acse-version',2}], [<<2>>,<<162>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). 'dec_Associate-source-diagnostic'(Tlv) -> 'dec_Associate-source-diagnostic'(Tlv, []). 'dec_Associate-source-diagnostic'(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'acse-service-user' {131073, V1} -> {'acse-service-user', begin Val1 = decode_integer(V1, [2]), number2name(Val1, [{null,0},{'no-reason-given',1},{'application-context-name-not-supported',2},{'calling-AP-title-not-recognized',3},{'calling-AP-invocation-identifier-not-recognized',4},{'calling-AE-qualifier-not-recognized',5},{'calling-AE-invocation-identifier-not-recognized',6},{'called-AP-title-not-recognized',7},{'called-AP-invocation-identifier-not-recognized',8},{'called-AE-qualifier-not-recognized',9},{'called-AE-invocation-identifier-not-recognized',10},{'authentication-mechanism-name-not-recognized',11},{'authentication-mechanism-name-required',12},{'authentication-failure',13},{'authentication-required',14}]) end }; %% 'acse-service-provider' {131074, V1} -> {'acse-service-provider', begin Val2 = decode_integer(V1, [2]), number2name(Val2, [{null,0},{'no-reason-given',1},{'no-common-acse-version',2}]) end }; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . %%================================ %% Association-information %%================================ 'enc_Association-information'(Val) -> 'enc_Association-information'(Val, [<<48>>]). 'enc_Association-information'(Val, TagIn) -> {EncBytes,EncLen} = 'enc_Association-information_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_Association-information_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_Association-information_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_EXTERNAL'(H, [<<40>>]), 'enc_Association-information_components'(T,[EncBytes|AccBytes], AccLen + EncLen). 'dec_Association-information'(Tlv) -> 'dec_Association-information'(Tlv, [16]). 'dec_Association-information'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_EXTERNAL'(V1, [8]) || V1 <- Tlv1]. %%================================ %% Authentication-value %%================================ 'enc_Authentication-value'(Val) -> 'enc_Authentication-value'(Val, []). 'enc_Authentication-value'(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of charstring -> encode_restricted_string(element(2,Val), [<<128>>]); bitstring -> encode_unnamed_bit_string(element(2,Val), [<<129>>]); external -> 'enc_EXTERNAL'(element(2,Val), [<<162>>]); other -> 'enc_Authentication-value_other'(element(2,Val), [<<163>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). %%================================ %% Authentication-value_other %%================================ 'enc_Authentication-value_other'(Val, TagIn) -> {_,Cindex1, Cindex2} = Val, Objother_mechanism_name = 'ACSE-1':'getenc_ObjectSet'( Cindex1), %%------------------------------------------------- %% attribute other-mechanism-name(1) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_object_identifier(Cindex1, [<<6>>]), %%------------------------------------------------- %% attribute other-mechanism-value(2) with type typefieldType %%------------------------------------------------- {TmpBytes2,_} = Objother_mechanism_name('Type', Cindex2, []), {EncBytes2,EncLen2} = encode_open_type(TmpBytes2, []) , BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). 'dec_Authentication-value'(Tlv) -> 'dec_Authentication-value'(Tlv, []). 'dec_Authentication-value'(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'charstring' {131072, V1} -> {charstring, begin binary_to_list(decode_restricted_string(V1, [])) end }; %% 'bitstring' {131073, V1} -> {bitstring, decode_native_bit_string(V1, [])}; %% 'external' {131074, V1} -> {external, 'dec_EXTERNAL'(V1, [])}; %% 'other' {131075, V1} -> {other, 'dec_Authentication-value_other'(V1, [])}; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . 'dec_Authentication-value_other'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute other-mechanism-name(1) with type OBJECT IDENTIFIER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_object_identifier(V1, [6]), %%------------------------------------------------- %% attribute other-mechanism-value(2) with type typefieldType %%------------------------------------------------- [V2|Tlv3] = Tlv2, Tmpterm1 = decode_open_type(V2, []), DecObjother_mechanism_nameTerm1 = 'ACSE-1':'getdec_ObjectSet'(Term1), Term2 = case (catch DecObjother_mechanism_nameTerm1('Type', Tmpterm1, [])) of {'EXIT', Reason1} -> exit({'Type not compatible with table constraint',Reason1}); Tmpterm2 -> Tmpterm2 end, case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, {'Authentication-value_other', Term1, Term2}. %%================================ %% Implementation-data %%================================ 'enc_Implementation-data'(Val) -> 'enc_Implementation-data'(Val, [<<25>>]). 'enc_Implementation-data'(Val, TagIn) -> encode_restricted_string(Val, TagIn). 'dec_Implementation-data'(Tlv) -> 'dec_Implementation-data'(Tlv, [25]). 'dec_Implementation-data'(Tlv, TagIn) -> begin binary_to_list(decode_restricted_string(Tlv, TagIn)) end . %%================================ %% Mechanism-name %%================================ 'enc_Mechanism-name'(Val) -> 'enc_Mechanism-name'(Val, [<<6>>]). 'enc_Mechanism-name'(Val, TagIn) -> encode_object_identifier(Val, TagIn). 'dec_Mechanism-name'(Tlv) -> 'dec_Mechanism-name'(Tlv, [6]). 'dec_Mechanism-name'(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% Release-request-reason %%================================ 'enc_Release-request-reason'(Val) -> 'enc_Release-request-reason'(Val, [<<2>>]). 'enc_Release-request-reason'(Val, TagIn) -> encode_integer(Val, [{normal,0},{urgent,1},{'user-defined',30}], TagIn). 'dec_Release-request-reason'(Tlv) -> 'dec_Release-request-reason'(Tlv, [2]). 'dec_Release-request-reason'(Tlv, TagIn) -> begin Val1 = decode_integer(Tlv, TagIn), number2name(Val1, [{normal,0},{urgent,1},{'user-defined',30}]) end . %%================================ %% Release-response-reason %%================================ 'enc_Release-response-reason'(Val) -> 'enc_Release-response-reason'(Val, [<<2>>]). 'enc_Release-response-reason'(Val, TagIn) -> encode_integer(Val, [{normal,0},{'not-finished',1},{'user-defined',30}], TagIn). 'dec_Release-response-reason'(Tlv) -> 'dec_Release-response-reason'(Tlv, [2]). 'dec_Release-response-reason'(Tlv, TagIn) -> begin Val1 = decode_integer(Tlv, TagIn), number2name(Val1, [{normal,0},{'not-finished',1},{'user-defined',30}]) end . %%================================ %% EXTERNAL %%================================ 'enc_EXTERNAL'(Val) -> 'enc_EXTERNAL'(Val, [<<40>>]). 'enc_EXTERNAL'(Val, TagIn) -> NewVal = transform_to_EXTERNAL1990(Val), {_,Cindex1, Cindex2, Cindex3, Cindex4} = NewVal, %%------------------------------------------------- %% attribute direct-reference(1) with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {EncBytes1,EncLen1} = case Cindex1 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_object_identifier(Cindex1, [<<6>>]) end, %%------------------------------------------------- %% attribute indirect-reference(2) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex2, [<<2>>]) end, %%------------------------------------------------- %% attribute data-value-descriptor(3) with type ObjectDescriptor OPTIONAL %%------------------------------------------------- {EncBytes3,EncLen3} = case Cindex3 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_restricted_string(Cindex3, [<<7>>]) end, %%------------------------------------------------- %% attribute encoding(4) with type CHOICE %%------------------------------------------------- {EncBytes4,EncLen4} = 'enc_EXTERNAL_encoding'(Cindex4, []), BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4, encode_tags(TagIn, BytesSoFar, LenSoFar). %%================================ %% EXTERNAL_encoding %%================================ 'enc_EXTERNAL_encoding'(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of 'single-ASN1-type' -> encode_open_type(element(2,Val), [<<160>>]); 'octet-aligned' -> encode_restricted_string(element(2,Val), [<<129>>]); arbitrary -> encode_unnamed_bit_string(element(2,Val), [<<130>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). 'dec_EXTERNAL'(Tlv) -> 'dec_EXTERNAL'(Tlv, [8]). 'dec_EXTERNAL'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute direct-reference(1) with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {Term1,Tlv2} = case Tlv1 of [{6,V1}|TempTlv2] -> {decode_object_identifier(V1, []), TempTlv2}; _ -> { asn1_NOVALUE, Tlv1} end, %%------------------------------------------------- %% attribute indirect-reference(2) with type INTEGER OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [{2,V2}|TempTlv3] -> {decode_integer(V2, []), TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, %%------------------------------------------------- %% attribute data-value-descriptor(3) with type ObjectDescriptor OPTIONAL %%------------------------------------------------- {Term3,Tlv4} = case Tlv3 of [{7,V3}|TempTlv4] -> {begin binary_to_list(decode_restricted_string(V3, [])) end , TempTlv4}; _ -> { asn1_NOVALUE, Tlv3} end, %%------------------------------------------------- %% attribute encoding(4) with type CHOICE %%------------------------------------------------- [V4|Tlv5] = Tlv4, Term4 = 'dec_EXTERNAL_encoding'(V4, []), case Tlv5 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv5}}}) % extra fields not allowed end, OldFormat={'EXTERNAL', Term1, Term2, Term3, Term4}, transform_to_EXTERNAL1994(OldFormat). 'dec_EXTERNAL_encoding'(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'single-ASN1-type' {131072, V1} -> {'single-ASN1-type', decode_open_type_as_binary(V1, [])}; %% 'octet-aligned' {131073, V1} -> {'octet-aligned', decode_octet_string(V1, [])}; %% 'arbitrary' {131074, V1} -> {arbitrary, decode_native_bit_string(V1, [])}; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . 'acse-as-id'() -> {2,2,1,0,1}. 'aCSE-id'() -> {2,2,3,1,1}. %%================================ %% ObjectSet %%================================ 'getenc_ObjectSet'(_) -> fun(_, Val, _RestPrimFieldName) -> case Val of {asn1_OPENTYPE,Bin} when is_binary(Bin) -> {Bin,byte_size(Bin)} end end. 'getdec_ObjectSet'(_) -> fun(_,Bytes, _RestPrimFieldName) -> case Bytes of Bin when is_binary(Bin) -> {asn1_OPENTYPE,Bin}; _ -> {asn1_OPENTYPE,ber_encode(Bytes)} end end. %%% %%% Run-time functions. %%% 'dialyzer-suppressions'(Arg) -> ok. ber_decode_nif(B) -> asn1rt_nif:decode_ber_tlv(B). ber_encode([Tlv]) -> ber_encode(Tlv); ber_encode(Tlv) when is_binary(Tlv) -> Tlv; ber_encode(Tlv) -> asn1rt_nif:encode_ber_tlv(Tlv). collect_parts(TlvList) -> collect_parts(TlvList, []). collect_parts([{_,L}|Rest], Acc) when is_list(L) -> collect_parts(Rest, [collect_parts(L)|Acc]); collect_parts([{3,<>}|Rest], _Acc) -> collect_parts_bit(Rest, [Bits], Unused); collect_parts([{_T,V}|Rest], Acc) -> collect_parts(Rest, [V|Acc]); collect_parts([], Acc) -> list_to_binary(lists:reverse(Acc)). collect_parts_bit([{3,<>}|Rest], Acc, Uacc) -> collect_parts_bit(Rest, [Bits|Acc], Unused + Uacc); collect_parts_bit([], Acc, Uacc) -> list_to_binary([Uacc|lists:reverse(Acc)]). dec_subidentifiers(<<>>, _Av, Al) -> lists:reverse(Al); dec_subidentifiers(<<1:1,H:7,T/binary>>, Av, Al) -> dec_subidentifiers(T, Av bsl 7 + H, Al); dec_subidentifiers(<>, Av, Al) -> dec_subidentifiers(T, 0, [Av bsl 7 + H|Al]). decode_bitstring2(1, Unused, <>) -> lists:sublist([B7,B6,B5,B4,B3,B2,B1,B0], 8 - Unused); decode_bitstring2(Len, Unused, <>) -> [B7,B6,B5,B4,B3,B2,B1,B0|decode_bitstring2(Len - 1, Unused, Buffer)]. decode_bitstring_NNL(BitList, NamedNumberList) -> decode_bitstring_NNL(BitList, NamedNumberList, 0, []). decode_bitstring_NNL([], _, _No, Result) -> lists:reverse(Result); decode_bitstring_NNL([B|BitList], [{Name,No}|NamedNumberList], No, Result) -> if B =:= 0 -> decode_bitstring_NNL(BitList, NamedNumberList, No + 1, Result); true -> decode_bitstring_NNL(BitList, NamedNumberList, No + 1, [Name|Result]) end; decode_bitstring_NNL([1|BitList], NamedNumberList, No, Result) -> decode_bitstring_NNL(BitList, NamedNumberList, No + 1, [{bit,No}|Result]); decode_bitstring_NNL([0|BitList], NamedNumberList, No, Result) -> decode_bitstring_NNL(BitList, NamedNumberList, No + 1, Result). decode_integer(Tlv, TagIn) -> Bin = match_tags(Tlv, TagIn), Len = byte_size(Bin), <> = Bin, Int. decode_named_bit_string(Buffer, NamedNumberList, Tags) -> case match_and_collect(Buffer, Tags) of <<0>> -> []; <> -> BitString = decode_bitstring2(byte_size(Bits), Unused, Bits), decode_bitstring_NNL(BitString, NamedNumberList) end. decode_native_bit_string(Buffer, Tags) -> case match_and_collect(Buffer, Tags) of <<0>> -> <<>>; <> -> Size = bit_size(Bits) - Unused, <> = Bits, Val end. decode_object_identifier(Tlv, Tags) -> Val = match_tags(Tlv, Tags), [AddedObjVal|ObjVals] = dec_subidentifiers(Val, 0, []), {Val1,Val2} = if AddedObjVal < 40 -> {0,AddedObjVal}; AddedObjVal < 80 -> {1,AddedObjVal - 40}; true -> {2,AddedObjVal - 80} end, list_to_tuple([Val1,Val2|ObjVals]). decode_octet_string(Tlv, TagsIn) -> Bin = match_and_collect(Tlv, TagsIn), binary:copy(Bin). decode_open_type(Tlv, TagIn) -> case match_tags(Tlv, TagIn) of Bin when is_binary(Bin) -> {InnerTlv,_} = ber_decode_nif(Bin), InnerTlv; TlvBytes -> TlvBytes end. decode_open_type_as_binary(Tlv, TagIn) -> ber_encode(match_tags(Tlv, TagIn)). decode_restricted_string(Tlv, TagsIn) -> match_and_collect(Tlv, TagsIn). do_encode_named_bit_string([FirstVal|RestVal], NamedBitList, TagIn) -> ToSetPos = get_all_bitposes([FirstVal|RestVal], NamedBitList, []), Size = lists:max(ToSetPos) + 1, BitList = make_and_set_list(Size, ToSetPos, 0), {Len,Unused,OctetList} = encode_bitstring(BitList), encode_tags(TagIn, [Unused|OctetList], Len + 1). e_object_identifier({'OBJECT IDENTIFIER',V}) -> e_object_identifier(V); e_object_identifier(V) when is_tuple(V) -> e_object_identifier(tuple_to_list(V)); e_object_identifier([E1,E2|Tail]) -> Head = 40 * E1 + E2, {H,Lh} = mk_object_val(Head), {R,Lr} = lists:mapfoldl(fun enc_obj_id_tail/2, 0, Tail), {[H|R],Lh + Lr}. enc_obj_id_tail(H, Len) -> {B,L} = mk_object_val(H), {B,Len + L}. encode_bitstring([B8,B7,B6,B5,B4,B3,B2,B1|Rest]) -> Val = B8 bsl 7 bor (B7 bsl 6) bor (B6 bsl 5) bor (B5 bsl 4) bor (B4 bsl 3) bor (B3 bsl 2) bor (B2 bsl 1) bor B1, encode_bitstring(Rest, [Val], 1); encode_bitstring(Val) -> {Unused,Octet} = unused_bitlist(Val, 7, 0), {1,Unused,[Octet]}. encode_bitstring([B8,B7,B6,B5,B4,B3,B2,B1|Rest], Ack, Len) -> Val = B8 bsl 7 bor (B7 bsl 6) bor (B6 bsl 5) bor (B5 bsl 4) bor (B4 bsl 3) bor (B3 bsl 2) bor (B2 bsl 1) bor B1, encode_bitstring(Rest, [Ack,Val], Len + 1); encode_bitstring([], Ack, Len) -> {Len,0,Ack}; encode_bitstring(Rest, Ack, Len) -> {Unused,Val} = unused_bitlist(Rest, 7, 0), {Len + 1,Unused,[Ack,Val]}. encode_integer(Val) -> Bytes = if Val >= 0 -> encode_integer_pos(Val, []); true -> encode_integer_neg(Val, []) end, {Bytes,length(Bytes)}. encode_integer(Val, NamedNumberList, Tag) when is_atom(Val) -> case lists:keyfind(Val, 1, NamedNumberList) of {_,NewVal} -> encode_tags(Tag, encode_integer(NewVal)); _ -> exit({error,{asn1,{encode_integer_namednumber,Val}}}) end; encode_integer(Val, _NamedNumberList, Tag) -> encode_tags(Tag, encode_integer(Val)). encode_integer(Val, Tag) when is_integer(Val) -> encode_tags(Tag, encode_integer(Val)); encode_integer(Val, _Tag) -> exit({error,{asn1,{encode_integer,Val}}}). encode_integer_neg(- 1, [B1|_T] = L) when B1 > 127 -> L; encode_integer_neg(N, Acc) -> encode_integer_neg(N bsr 8, [N band 255|Acc]). encode_integer_pos(0, [B|_Acc] = L) when B < 128 -> L; encode_integer_pos(N, Acc) -> encode_integer_pos(N bsr 8, [N band 255|Acc]). encode_length(L) when L =< 127 -> {[L],1}; encode_length(L) -> Oct = minimum_octets(L), Len = length(Oct), if Len =< 126 -> {[128 bor Len|Oct],Len + 1}; true -> exit({error,{asn1,too_long_length_oct,Len}}) end. encode_named_bit_string([H|_] = Bits, NamedBitList, TagIn) when is_atom(H) -> do_encode_named_bit_string(Bits, NamedBitList, TagIn); encode_named_bit_string([{bit,_}|_] = Bits, NamedBitList, TagIn) -> do_encode_named_bit_string(Bits, NamedBitList, TagIn); encode_named_bit_string(Bits, _NamedBitList, TagIn) when is_bitstring(Bits) -> encode_unnamed_bit_string(Bits, TagIn). encode_object_identifier(Val, TagIn) -> encode_tags(TagIn, e_object_identifier(Val)). encode_open_type(Val, T) when is_list(Val) -> encode_open_type(list_to_binary(Val), T); encode_open_type(Val, Tag) -> encode_tags(Tag, Val, byte_size(Val)). encode_restricted_string(OctetList, TagIn) when is_binary(OctetList) -> encode_tags(TagIn, OctetList, byte_size(OctetList)); encode_restricted_string(OctetList, TagIn) when is_list(OctetList) -> encode_tags(TagIn, OctetList, length(OctetList)). encode_tags(TagIn, {BytesSoFar,LenSoFar}) -> encode_tags(TagIn, BytesSoFar, LenSoFar). encode_tags([Tag|Trest], BytesSoFar, LenSoFar) -> {Bytes2,L2} = encode_length(LenSoFar), encode_tags(Trest, [Tag,Bytes2|BytesSoFar], LenSoFar + byte_size(Tag) + L2); encode_tags([], BytesSoFar, LenSoFar) -> {BytesSoFar,LenSoFar}. encode_unnamed_bit_string(Bits, TagIn) -> Unused = (8 - bit_size(Bits) band 7) band 7, Bin = <>, encode_tags(TagIn, Bin, byte_size(Bin)). get_all_bitposes([{bit,ValPos}|Rest], NamedBitList, Ack) -> get_all_bitposes(Rest, NamedBitList, [ValPos|Ack]); get_all_bitposes([Val|Rest], NamedBitList, Ack) when is_atom(Val) -> case lists:keyfind(Val, 1, NamedBitList) of {_ValName,ValPos} -> get_all_bitposes(Rest, NamedBitList, [ValPos|Ack]); _ -> exit({error,{asn1,{bitstring_namedbit,Val}}}) end; get_all_bitposes([], _NamedBitList, Ack) -> lists:sort(Ack). make_and_set_list(0, [], _) -> []; make_and_set_list(0, _, _) -> exit({error,{asn1,bitstring_sizeconstraint}}); make_and_set_list(Len, [XPos|SetPos], XPos) -> [1|make_and_set_list(Len - 1, SetPos, XPos + 1)]; make_and_set_list(Len, [Pos|SetPos], XPos) -> [0|make_and_set_list(Len - 1, [Pos|SetPos], XPos + 1)]; make_and_set_list(Len, [], XPos) -> [0|make_and_set_list(Len - 1, [], XPos + 1)]. match_and_collect(Tlv, TagsIn) -> Val = match_tags(Tlv, TagsIn), case Val of [_|_] = PartList -> collect_parts(PartList); Bin when is_binary(Bin) -> Bin end. match_tags({T,V}, [T]) -> V; match_tags({T,V}, [T|Tt]) -> match_tags(V, Tt); match_tags([{T,V}], [T|Tt]) -> match_tags(V, Tt); match_tags([{T,_V}|_] = Vlist, [T]) -> Vlist; match_tags(Tlv, []) -> Tlv; match_tags({Tag,_V} = Tlv, [T|_Tt]) -> exit({error,{asn1,{wrong_tag,{{expected,T},{got,Tag,Tlv}}}}}). minimum_octets(0, Acc) -> Acc; minimum_octets(Val, Acc) -> minimum_octets(Val bsr 8, [Val band 255|Acc]). minimum_octets(Val) -> minimum_octets(Val, []). mk_object_val(0, Ack, Len) -> {Ack,Len}; mk_object_val(Val, Ack, Len) -> mk_object_val(Val bsr 7, [Val band 127 bor 128|Ack], Len + 1). mk_object_val(Val) when Val =< 127 -> {[255 band Val],1}; mk_object_val(Val) -> mk_object_val(Val bsr 7, [Val band 127], 1). number2name(Int, NamedNumberList) -> case lists:keyfind(Int, 2, NamedNumberList) of {NamedVal,_} -> NamedVal; _ -> Int end. skip_ExtensionAdditions([], _Tags) -> []; skip_ExtensionAdditions([{Tag,_}|Rest] = TLV, Tags) -> case [ X || X = T <- Tags, T =:= Tag ] of [] -> skip_ExtensionAdditions(Rest, Tags); _ -> TLV end. transform_to_EXTERNAL1990(['EXTERNAL'|Rest], Acc) -> transform_to_EXTERNAL1990(Rest, ['EXTERNAL'|Acc]); transform_to_EXTERNAL1990([{syntax,Syntax}|Rest], Acc) -> transform_to_EXTERNAL1990(Rest, [asn1_NOVALUE,Syntax|Acc]); transform_to_EXTERNAL1990([{'presentation-context-id',PCid}|Rest], Acc) -> transform_to_EXTERNAL1990(Rest, [PCid,asn1_NOVALUE|Acc]); transform_to_EXTERNAL1990([{'context-negotiation',Context_negot}|Rest], Acc) -> {_,Presentation_Cid,Transfer_syntax} = Context_negot, transform_to_EXTERNAL1990(Rest, [Presentation_Cid,Transfer_syntax|Acc]); transform_to_EXTERNAL1990([asn1_NOVALUE|Rest], Acc) -> transform_to_EXTERNAL1990(Rest, [asn1_NOVALUE|Acc]); transform_to_EXTERNAL1990([Data_val_desc,Data_value], Acc) when is_list(Data_value); is_binary(Data_value) -> list_to_tuple(lists:reverse([{'octet-aligned',Data_value}, Data_val_desc| Acc])); transform_to_EXTERNAL1990([Data_val_desc,Data_value], Acc) when is_binary(Data_value) -> list_to_tuple(lists:reverse([{'single-ASN1-type',Data_value}, Data_val_desc| Acc])); transform_to_EXTERNAL1990([Data_value], Acc) when is_list(Data_value); is_binary(Data_value) -> list_to_tuple(lists:reverse([{'octet-aligned',Data_value}|Acc])). transform_to_EXTERNAL1990({_,_,_,_} = Val) -> transform_to_EXTERNAL1990(tuple_to_list(Val), []); transform_to_EXTERNAL1990(Val) when is_tuple(Val) -> Val. transform_to_EXTERNAL1994({'EXTERNAL',DRef,IndRef,Data_v_desc,Encoding} = V) -> Identification = case {DRef,IndRef} of {DRef,asn1_NOVALUE} -> {syntax,DRef}; {asn1_NOVALUE,IndRef} -> {'presentation-context-id',IndRef}; _ -> {'context-negotiation', {'EXTERNAL_identification_context-negotiation', IndRef, DRef}} end, case Encoding of {'octet-aligned',Val} when is_list(Val); is_binary(Val) -> {'EXTERNAL',Identification,Data_v_desc,Val}; _ -> V end. unused_bitlist([], Trail, Ack) -> {Trail + 1,Ack}; unused_bitlist([Bit|Rest], Trail, Ack) -> unused_bitlist(Rest, Trail - 1, Bit bsl Trail bor Ack).