Packages

MAIL Simple Message Delivery Protocol

Current section

Files

Jump to
mail420 src IPMSHeadingExtensions.erl
Raw

src/IPMSHeadingExtensions.erl

%% Generated by the Erlang ASN.1 BER compiler. Version: 5.1
%% Purpose: Encoding and decoding of the types in IPMSHeadingExtensions.
-module('IPMSHeadingExtensions').
-compile(nowarn_unused_vars).
-dialyzer(no_improper_lists).
-dialyzer(no_match).
-include("IPMSHeadingExtensions.hrl").
-asn1_info([{vsn,'5.1'},
{module,'IPMSHeadingExtensions'},
{options,[warnings,ber,errors,
{cwd,"/Users/maxim/depot/synrc/mail/priv/mhs"},
{outdir,"/Users/maxim/depot/synrc/mail/priv/mhs"},
{i,"."},
{i,"/Users/maxim/depot/synrc/mail/priv/mhs"}]}]).
-export([encoding_rule/0,maps/0,bit_string_format/0,
legacy_erlang_types/0]).
-export(['dialyzer-suppressions'/1]).
-export([
enc_IncompleteCopy/2,
enc_Language/2,
enc_AutoSubmitted/2,
enc_BodyPartSignatures/2,
enc_BodyPartNumber/2,
enc_BodyPartSignature/2,
enc_IPMSecurityLabel/2,
enc_BodyPartSecurityLabel/2,
enc_AuthorizationTime/2,
enc_CirculationList/2,
enc_CirculationMember/2,
enc_Checkmark/2,
enc_CirculationTime/2,
enc_CirculationSignature/2,
enc_CirculationSignatureAlgorithmIdentifier/2,
enc_DistributionCodes/2,
enc_DistributionCode/2,
enc_AlphaCode/2,
enc_ExtendedSubject/2,
enc_InformationCategories/2,
enc_InformationCategory/2,
enc_DescriptionString/2,
enc_ManualHandlingInstructions/2,
enc_ManualHandlingInstruction/2,
enc_OriginatorsReference/2,
enc_PrecedencePolicyIdentifier/2,
enc_Precedence/2
]).
-export([
dec_IncompleteCopy/2,
dec_Language/2,
dec_AutoSubmitted/2,
dec_BodyPartSignatures/2,
dec_BodyPartNumber/2,
dec_BodyPartSignature/2,
dec_IPMSecurityLabel/2,
dec_BodyPartSecurityLabel/2,
dec_AuthorizationTime/2,
dec_CirculationList/2,
dec_CirculationMember/2,
dec_Checkmark/2,
dec_CirculationTime/2,
dec_CirculationSignature/2,
dec_CirculationSignatureAlgorithmIdentifier/2,
dec_DistributionCodes/2,
dec_DistributionCode/2,
dec_AlphaCode/2,
dec_ExtendedSubject/2,
dec_InformationCategories/2,
dec_InformationCategory/2,
dec_DescriptionString/2,
dec_ManualHandlingInstructions/2,
dec_ManualHandlingInstruction/2,
dec_OriginatorsReference/2,
dec_PrecedencePolicyIdentifier/2,
dec_Precedence/2
]).
-export([
'enc_incomplete-copy'/3,
enc_languages/3,
'enc_auto-submitted'/3,
'enc_body-part-signatures'/3,
'enc_ipm-security-label'/3,
'enc_authorization-time'/3,
'enc_circulation-list-recipients'/3,
'enc_circulation-list-indicator'/3,
'enc_distribution-codes'/3,
'enc_extended-subject'/3,
'enc_information-category'/3,
'enc_manual-handling-instructions'/3,
'enc_originators-reference'/3,
'enc_precedence-policy-identifier'/3,
enc_precedence/3
]).
-export([
'dec_incomplete-copy'/3,
dec_languages/3,
'dec_auto-submitted'/3,
'dec_body-part-signatures'/3,
'dec_ipm-security-label'/3,
'dec_authorization-time'/3,
'dec_circulation-list-recipients'/3,
'dec_circulation-list-indicator'/3,
'dec_distribution-codes'/3,
'dec_extended-subject'/3,
'dec_information-category'/3,
'dec_manual-handling-instructions'/3,
'dec_originators-reference'/3,
'dec_precedence-policy-identifier'/3,
dec_precedence/3
]).
-export([info/0]).
-export([encode/2,decode/2]).
encoding_rule() -> ber.
maps() -> false.
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:Stk when Class =:= error; Class =:= exit ->
case Exception of
{error,{asn1,Reason}} ->
{error,{asn1,{Reason,Stk}}};
Reason ->
{error,{asn1,{Reason,Stk}}}
end
end.
decode(Type, Data) ->
try
Result = decode_disp(Type, element(1, ber_decode_nif(Data))),
{ok,Result}
catch
Class:Exception:Stk when Class =:= error; Class =:= exit ->
case Exception of
{error,{asn1,Reason}} ->
{error,{asn1,{Reason,Stk}}};
Reason ->
{error,{asn1,{Reason,Stk}}}
end
end.
encode_disp('IncompleteCopy', Data) -> enc_IncompleteCopy(Data);
encode_disp('Language', Data) -> enc_Language(Data);
encode_disp('AutoSubmitted', Data) -> enc_AutoSubmitted(Data);
encode_disp('BodyPartSignatures', Data) -> enc_BodyPartSignatures(Data);
encode_disp('BodyPartNumber', Data) -> enc_BodyPartNumber(Data);
encode_disp('BodyPartSignature', Data) -> enc_BodyPartSignature(Data);
encode_disp('IPMSecurityLabel', Data) -> enc_IPMSecurityLabel(Data);
encode_disp('BodyPartSecurityLabel', Data) -> enc_BodyPartSecurityLabel(Data);
encode_disp('AuthorizationTime', Data) -> enc_AuthorizationTime(Data);
encode_disp('CirculationList', Data) -> enc_CirculationList(Data);
encode_disp('CirculationMember', Data) -> enc_CirculationMember(Data);
encode_disp('Checkmark', Data) -> enc_Checkmark(Data);
encode_disp('CirculationTime', Data) -> enc_CirculationTime(Data);
encode_disp('CirculationSignature', Data) -> enc_CirculationSignature(Data);
encode_disp('CirculationSignatureAlgorithmIdentifier', Data) -> enc_CirculationSignatureAlgorithmIdentifier(Data);
encode_disp('DistributionCodes', Data) -> enc_DistributionCodes(Data);
encode_disp('DistributionCode', Data) -> enc_DistributionCode(Data);
encode_disp('AlphaCode', Data) -> enc_AlphaCode(Data);
encode_disp('ExtendedSubject', Data) -> enc_ExtendedSubject(Data);
encode_disp('InformationCategories', Data) -> enc_InformationCategories(Data);
encode_disp('InformationCategory', Data) -> enc_InformationCategory(Data);
encode_disp('DescriptionString', Data) -> enc_DescriptionString(Data);
encode_disp('ManualHandlingInstructions', Data) -> enc_ManualHandlingInstructions(Data);
encode_disp('ManualHandlingInstruction', Data) -> enc_ManualHandlingInstruction(Data);
encode_disp('OriginatorsReference', Data) -> enc_OriginatorsReference(Data);
encode_disp('PrecedencePolicyIdentifier', Data) -> enc_PrecedencePolicyIdentifier(Data);
encode_disp('Precedence', Data) -> enc_Precedence(Data);
encode_disp(Type, _Data) -> exit({error,{asn1,{undefined_type,Type}}}).
decode_disp('IncompleteCopy', Data) -> dec_IncompleteCopy(Data);
decode_disp('Language', Data) -> dec_Language(Data);
decode_disp('AutoSubmitted', Data) -> dec_AutoSubmitted(Data);
decode_disp('BodyPartSignatures', Data) -> dec_BodyPartSignatures(Data);
decode_disp('BodyPartNumber', Data) -> dec_BodyPartNumber(Data);
decode_disp('BodyPartSignature', Data) -> dec_BodyPartSignature(Data);
decode_disp('IPMSecurityLabel', Data) -> dec_IPMSecurityLabel(Data);
decode_disp('BodyPartSecurityLabel', Data) -> dec_BodyPartSecurityLabel(Data);
decode_disp('AuthorizationTime', Data) -> dec_AuthorizationTime(Data);
decode_disp('CirculationList', Data) -> dec_CirculationList(Data);
decode_disp('CirculationMember', Data) -> dec_CirculationMember(Data);
decode_disp('Checkmark', Data) -> dec_Checkmark(Data);
decode_disp('CirculationTime', Data) -> dec_CirculationTime(Data);
decode_disp('CirculationSignature', Data) -> dec_CirculationSignature(Data);
decode_disp('CirculationSignatureAlgorithmIdentifier', Data) -> dec_CirculationSignatureAlgorithmIdentifier(Data);
decode_disp('DistributionCodes', Data) -> dec_DistributionCodes(Data);
decode_disp('DistributionCode', Data) -> dec_DistributionCode(Data);
decode_disp('AlphaCode', Data) -> dec_AlphaCode(Data);
decode_disp('ExtendedSubject', Data) -> dec_ExtendedSubject(Data);
decode_disp('InformationCategories', Data) -> dec_InformationCategories(Data);
decode_disp('InformationCategory', Data) -> dec_InformationCategory(Data);
decode_disp('DescriptionString', Data) -> dec_DescriptionString(Data);
decode_disp('ManualHandlingInstructions', Data) -> dec_ManualHandlingInstructions(Data);
decode_disp('ManualHandlingInstruction', Data) -> dec_ManualHandlingInstruction(Data);
decode_disp('OriginatorsReference', Data) -> dec_OriginatorsReference(Data);
decode_disp('PrecedencePolicyIdentifier', Data) -> dec_PrecedencePolicyIdentifier(Data);
decode_disp('Precedence', Data) -> dec_Precedence(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.
%%================================
%% IncompleteCopy
%%================================
enc_IncompleteCopy(Val) ->
enc_IncompleteCopy(Val, [<<5>>]).
enc_IncompleteCopy(Val, TagIn) ->
encode_null(Val, TagIn).
dec_IncompleteCopy(Tlv) ->
dec_IncompleteCopy(Tlv, [5]).
dec_IncompleteCopy(Tlv, TagIn) ->
decode_null(Tlv, TagIn).
%%================================
%% Language
%%================================
enc_Language(Val) ->
enc_Language(Val, [<<19>>]).
enc_Language(Val, TagIn) ->
encode_restricted_string(Val, TagIn).
dec_Language(Tlv) ->
dec_Language(Tlv, [19]).
dec_Language(Tlv, TagIn) ->
begin
Val1 = decode_restricted_string(Tlv, TagIn),
C1 = byte_size(Val1),
if 2 =< C1, C1 =< 5 ->
binary_to_list(Val1);
true ->
exit({error,{asn1,bad_range}})
end
end.
%%================================
%% AutoSubmitted
%%================================
enc_AutoSubmitted(Val) ->
enc_AutoSubmitted(Val, [<<10>>]).
enc_AutoSubmitted(Val, TagIn) ->
case Val of
'not-auto-submitted' -> encode_tags(TagIn, [0], 1);
'auto-generated' -> encode_tags(TagIn, [1], 1);
'auto-replied' -> encode_tags(TagIn, [2], 1);
Enumval1 -> exit({error,{asn1, {enumerated_not_in_range,Enumval1}}})
end.
dec_AutoSubmitted(Tlv) ->
dec_AutoSubmitted(Tlv, [10]).
dec_AutoSubmitted(Tlv, TagIn) ->
case decode_integer(Tlv, TagIn) of
0 -> 'not-auto-submitted';
1 -> 'auto-generated';
2 -> 'auto-replied';
Default1 -> exit({error,{asn1,{illegal_enumerated,Default1}}})
end.
%%================================
%% BodyPartSignatures
%%================================
enc_BodyPartSignatures(Val) ->
enc_BodyPartSignatures(Val, [<<49>>]).
enc_BodyPartSignatures(Val, TagIn) ->
{EncBytes,EncLen} = 'enc_BodyPartSignatures_components'(Val,[],0),
encode_tags(TagIn, EncBytes, EncLen).
'enc_BodyPartSignatures_components'([], AccBytes, AccLen) ->
{lists:reverse(AccBytes),AccLen};
'enc_BodyPartSignatures_components'([H|T],AccBytes, AccLen) ->
{EncBytes,EncLen} = 'enc_BodyPartSignatures_SETOF'(H, [<<49>>]),
'enc_BodyPartSignatures_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
%%================================
%% BodyPartSignatures_SETOF
%%================================
enc_BodyPartSignatures_SETOF(Val, TagIn) ->
{_,Cindex1,Cindex2,Cindex3,Cindex4} = Val,
%%-------------------------------------------------
%% attribute body-part-number(1) with type INTEGER
%%-------------------------------------------------
{EncBytes1,EncLen1} = encode_integer(Cindex1, [<<2>>]),
%%-------------------------------------------------
%% attribute body-part-signature(2) External IPMSHeadingExtensions:BodyPartSignature
%%-------------------------------------------------
{EncBytes2,EncLen2} = 'enc_BodyPartSignature'(Cindex2, [<<48>>]),
%%-------------------------------------------------
%% attribute originator-certificate-selector(3) External CertificateExtensions:CertificateAssertion OPTIONAL
%%-------------------------------------------------
{EncBytes3,EncLen3} = case Cindex3 of
asn1_NOVALUE -> {<<>>,0};
_ ->
'CertificateExtensions':'enc_CertificateAssertion'(Cindex3, [<<161>>])
end,
%%-------------------------------------------------
%% attribute originator-certificates(4) External MTSAbstractService:ExtendedCertificates OPTIONAL
%%-------------------------------------------------
{EncBytes4,EncLen4} = case Cindex4 of
asn1_NOVALUE -> {<<>>,0};
_ ->
'MTSAbstractService':'enc_ExtendedCertificates'(Cindex4, [<<160>>])
end,
BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4],
LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4,
encode_tags(TagIn, BytesSoFar, LenSoFar).
dec_BodyPartSignatures(Tlv) ->
dec_BodyPartSignatures(Tlv, [17]).
dec_BodyPartSignatures(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
['dec_BodyPartSignatures_SETOF'(V1, [17]) || V1 <- Tlv1].
'dec_BodyPartSignatures_SETOF'(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
SetFun = fun(FunTlv) ->
case FunTlv of
%body-part-number
TTlv = {2,_} ->
{1, TTlv};
%body-part-signature
TTlv = {16,_} ->
{2, TTlv};
%originator-certificate-selector
TTlv = {131073,_} ->
{3, TTlv};
%originator-certificates
TTlv = {131072,_} ->
{4, TTlv};
Else ->
{5, Else}
end
end,
PositionList = [SetFun(TempTlv)|| TempTlv <- Tlv1],
Tlv2 = [Stlv || {_,Stlv} <- lists:sort(PositionList)],
%%-------------------------------------------------
%% attribute body-part-number(1) with type INTEGER
%%-------------------------------------------------
[V1|Tlv3] = Tlv2,
Term1 = begin
Val1 = decode_integer(V1, [2]),
if 1 =< Val1, Val1 =< 'MAX' ->
Val1;
true ->
exit({error,{asn1,bad_range}})
end
end,
%%-------------------------------------------------
%% attribute body-part-signature(2) External IPMSHeadingExtensions:BodyPartSignature
%%-------------------------------------------------
[V2|Tlv4] = Tlv3,
Term2 = 'dec_BodyPartSignature'(V2, [16]),
%%-------------------------------------------------
%% attribute originator-certificate-selector(3) External CertificateExtensions:CertificateAssertion OPTIONAL
%%-------------------------------------------------
{Term3,Tlv5} = case Tlv4 of
[{131073,V3}|TempTlv5] ->
{'CertificateExtensions':'dec_CertificateAssertion'(V3, []), TempTlv5};
_ ->
{ asn1_NOVALUE, Tlv4}
end,
%%-------------------------------------------------
%% attribute originator-certificates(4) External MTSAbstractService:ExtendedCertificates OPTIONAL
%%-------------------------------------------------
{Term4,Tlv6} = case Tlv5 of
[{131072,V4}|TempTlv6] ->
{'MTSAbstractService':'dec_ExtendedCertificates'(V4, []), TempTlv6};
_ ->
{ asn1_NOVALUE, Tlv5}
end,
case Tlv6 of [] -> true; _ -> true end, % ... extra fields skipped
Res1 = {'BodyPartSignatures_SETOF',Term1,Term2,Term3,Term4},
Res1.
%%================================
%% BodyPartNumber
%%================================
enc_BodyPartNumber(Val) ->
enc_BodyPartNumber(Val, [<<2>>]).
enc_BodyPartNumber(Val, TagIn) ->
encode_integer(Val, TagIn).
dec_BodyPartNumber(Tlv) ->
dec_BodyPartNumber(Tlv, [2]).
dec_BodyPartNumber(Tlv, TagIn) ->
begin
Val1 = decode_integer(Tlv, TagIn),
if 1 =< Val1, Val1 =< 'MAX' ->
Val1;
true ->
exit({error,{asn1,bad_range}})
end
end.
%%================================
%% BodyPartSignature
%%================================
enc_BodyPartSignature(Val) ->
enc_BodyPartSignature(Val, [<<48>>]).
enc_BodyPartSignature(Val, TagIn) ->
{_,Cindex1,Cindex2} = Val,
%%-------------------------------------------------
%% attribute algorithmIdentifier(1) External AuthenticationFramework:AlgorithmIdentifier
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'AuthenticationFramework':'enc_AlgorithmIdentifier'(Cindex1, [<<48>>]),
%%-------------------------------------------------
%% attribute encrypted(2) with type BIT STRING
%%-------------------------------------------------
{EncBytes2,EncLen2} = encode_unnamed_bit_string(Cindex2, [<<3>>]),
BytesSoFar = [EncBytes1, EncBytes2],
LenSoFar = EncLen1 + EncLen2,
encode_tags(TagIn, BytesSoFar, LenSoFar).
dec_BodyPartSignature(Tlv) ->
dec_BodyPartSignature(Tlv, [16]).
dec_BodyPartSignature(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
%%-------------------------------------------------
%% attribute algorithmIdentifier(1) External AuthenticationFramework:AlgorithmIdentifier
%%-------------------------------------------------
[V1|Tlv2] = Tlv1,
Term1 = 'AuthenticationFramework':'dec_AlgorithmIdentifier'(V1, [16]),
%%-------------------------------------------------
%% attribute encrypted(2) with type BIT STRING
%%-------------------------------------------------
[V2|Tlv3] = Tlv2,
Term2 = decode_native_bit_string(V2, [3]),
case Tlv3 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed
end,
Res1 = {'BodyPartSignature',Term1,Term2},
Res1.
%%================================
%% IPMSecurityLabel
%%================================
enc_IPMSecurityLabel(Val) ->
enc_IPMSecurityLabel(Val, [<<48>>]).
enc_IPMSecurityLabel(Val, TagIn) ->
{_,Cindex1,Cindex2,Cindex3} = Val,
%%-------------------------------------------------
%% attribute content-security-label(1) External MTSAbstractService:SecurityLabel
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'MTSAbstractService':'enc_SecurityLabel'(Cindex1, [<<160>>]),
%%-------------------------------------------------
%% attribute heading-security-label(2) External MTSAbstractService:SecurityLabel OPTIONAL
%%-------------------------------------------------
{EncBytes2,EncLen2} = case Cindex2 of
asn1_NOVALUE -> {<<>>,0};
_ ->
'MTSAbstractService':'enc_SecurityLabel'(Cindex2, [<<161>>])
end,
%%-------------------------------------------------
%% attribute body-part-security-labels(3) with type SEQUENCE OF OPTIONAL
%%-------------------------------------------------
{EncBytes3,EncLen3} = case Cindex3 of
asn1_NOVALUE -> {<<>>,0};
_ ->
'enc_IPMSecurityLabel_body-part-security-labels'(Cindex3, [<<162>>])
end,
BytesSoFar = [EncBytes1, EncBytes2, EncBytes3],
LenSoFar = EncLen1 + EncLen2 + EncLen3,
encode_tags(TagIn, BytesSoFar, LenSoFar).
%%================================
%% IPMSecurityLabel_body-part-security-labels
%%================================
'enc_IPMSecurityLabel_body-part-security-labels'(Val, TagIn) ->
{EncBytes,EncLen} = 'enc_IPMSecurityLabel_body-part-security-labels_components'(Val,[],0),
encode_tags(TagIn, EncBytes, EncLen).
'enc_IPMSecurityLabel_body-part-security-labels_components'([], AccBytes, AccLen) ->
{lists:reverse(AccBytes),AccLen};
'enc_IPMSecurityLabel_body-part-security-labels_components'([H|T],AccBytes, AccLen) ->
{EncBytes,EncLen} = 'enc_BodyPartSecurityLabel'(H, []),
'enc_IPMSecurityLabel_body-part-security-labels_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
dec_IPMSecurityLabel(Tlv) ->
dec_IPMSecurityLabel(Tlv, [16]).
dec_IPMSecurityLabel(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
%%-------------------------------------------------
%% attribute content-security-label(1) External MTSAbstractService:SecurityLabel
%%-------------------------------------------------
[V1|Tlv2] = Tlv1,
Term1 = 'MTSAbstractService':'dec_SecurityLabel'(V1, [131072]),
%%-------------------------------------------------
%% attribute heading-security-label(2) External MTSAbstractService:SecurityLabel OPTIONAL
%%-------------------------------------------------
{Term2,Tlv3} = case Tlv2 of
[{131073,V2}|TempTlv3] ->
{'MTSAbstractService':'dec_SecurityLabel'(V2, []), TempTlv3};
_ ->
{ asn1_NOVALUE, Tlv2}
end,
%%-------------------------------------------------
%% attribute body-part-security-labels(3) with type SEQUENCE OF OPTIONAL
%%-------------------------------------------------
{Term3,Tlv4} = case Tlv3 of
[{131074,V3}|TempTlv4] ->
{'dec_IPMSecurityLabel_body-part-security-labels'(V3, []), TempTlv4};
_ ->
{ asn1_NOVALUE, Tlv3}
end,
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'IPMSecurityLabel',Term1,Term2,Term3},
Res1.
'dec_IPMSecurityLabel_body-part-security-labels'(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
['dec_BodyPartSecurityLabel'(V1, []) || V1 <- Tlv1].
%%================================
%% BodyPartSecurityLabel
%%================================
enc_BodyPartSecurityLabel(Val) ->
enc_BodyPartSecurityLabel(Val, []).
enc_BodyPartSecurityLabel(Val, TagIn) ->
{EncBytes,EncLen} = case element(1,Val) of
'body-part-unlabelled' ->
encode_null(element(2,Val), [<<128>>]);
'body-part-security-label' ->
'MTSAbstractService':'enc_SecurityLabel'(element(2,Val), [<<161>>]);
Else ->
exit({error,{asn1,{invalid_choice_type,Else}}})
end,
encode_tags(TagIn, EncBytes, EncLen).
dec_BodyPartSecurityLabel(Tlv) ->
dec_BodyPartSecurityLabel(Tlv, []).
dec_BodyPartSecurityLabel(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
%% 'body-part-unlabelled'
{131072, V1} ->
{'body-part-unlabelled', decode_null(V1, [])};
%% 'body-part-security-label'
{131073, V1} ->
{'body-part-security-label', 'MTSAbstractService':'dec_SecurityLabel'(V1, [])};
Else ->
exit({error,{asn1,{invalid_choice_tag,Else}}})
end
.
%%================================
%% AuthorizationTime
%%================================
enc_AuthorizationTime(Val) ->
enc_AuthorizationTime(Val, [<<24>>]).
enc_AuthorizationTime(Val, TagIn) ->
encode_restricted_string(Val, TagIn).
dec_AuthorizationTime(Tlv) ->
dec_AuthorizationTime(Tlv, [24]).
dec_AuthorizationTime(Tlv, TagIn) ->
begin
binary_to_list(decode_restricted_string(Tlv, TagIn))
end
.
%%================================
%% CirculationList
%%================================
enc_CirculationList(Val) ->
enc_CirculationList(Val, [<<48>>]).
enc_CirculationList(Val, TagIn) ->
{EncBytes,EncLen} = 'enc_CirculationList_components'(Val,[],0),
encode_tags(TagIn, EncBytes, EncLen).
'enc_CirculationList_components'([], AccBytes, AccLen) ->
{lists:reverse(AccBytes),AccLen};
'enc_CirculationList_components'([H|T],AccBytes, AccLen) ->
{EncBytes,EncLen} = 'enc_CirculationMember'(H, [<<49>>]),
'enc_CirculationList_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
dec_CirculationList(Tlv) ->
dec_CirculationList(Tlv, [16]).
dec_CirculationList(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
['dec_CirculationMember'(V1, [17]) || V1 <- Tlv1].
%%================================
%% CirculationMember
%%================================
enc_CirculationMember(Val) ->
enc_CirculationMember(Val, [<<49>>]).
enc_CirculationMember(Val, TagIn) ->
{_,Cindex1,Cindex2} = Val,
%%-------------------------------------------------
%% attribute circulation-recipient(1) External IPMSInformationObjects:RecipientSpecifier
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'IPMSInformationObjects':'enc_RecipientSpecifier'(Cindex1, [<<49>>]),
%%-------------------------------------------------
%% attribute checked(2) External IPMSHeadingExtensions:Checkmark OPTIONAL
%%-------------------------------------------------
{EncBytes2,EncLen2} = case Cindex2 of
asn1_NOVALUE -> {<<>>,0};
_ ->
'enc_Checkmark'(Cindex2, [])
end,
BytesSoFar = [EncBytes1, EncBytes2],
LenSoFar = EncLen1 + EncLen2,
encode_tags(TagIn, BytesSoFar, LenSoFar).
dec_CirculationMember(Tlv) ->
dec_CirculationMember(Tlv, [17]).
dec_CirculationMember(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
SetFun = fun(FunTlv) ->
case FunTlv of
%circulation-recipient
TTlv = {17,_} ->
{1, TTlv};
%checked
TTlv = {5,_} ->
{2, TTlv};
TTlv = {24,_} ->
{2, TTlv};
TTlv = {16,_} ->
{2, TTlv};
Else ->
{3, Else}
end
end,
PositionList = [SetFun(TempTlv)|| TempTlv <- Tlv1],
Tlv2 = [Stlv || {_,Stlv} <- lists:sort(PositionList)],
%%-------------------------------------------------
%% attribute circulation-recipient(1) External IPMSInformationObjects:RecipientSpecifier
%%-------------------------------------------------
[V1|Tlv3] = Tlv2,
Term1 = 'IPMSInformationObjects':'dec_RecipientSpecifier'(V1, [17]),
%%-------------------------------------------------
%% attribute checked(2) External IPMSHeadingExtensions:Checkmark OPTIONAL
%%-------------------------------------------------
{Term2,Tlv4} = case Tlv3 of
[V2 = {5,_}|TempTlv4] ->
{'dec_Checkmark'(V2, []), TempTlv4};
[V2 = {24,_}|TempTlv4] ->
{'dec_Checkmark'(V2, []), TempTlv4};
[V2 = {16,_}|TempTlv4] ->
{'dec_Checkmark'(V2, []), TempTlv4};
_ ->
{ asn1_NOVALUE, Tlv3}
end,
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'CirculationMember',Term1,Term2},
Res1.
%%================================
%% Checkmark
%%================================
enc_Checkmark(Val) ->
enc_Checkmark(Val, []).
enc_Checkmark(Val, TagIn) ->
{EncBytes,EncLen} = case element(1,Val) of
simple ->
encode_null(element(2,Val), [<<5>>]);
timestamped ->
encode_restricted_string(element(2,Val), [<<24>>]);
signed ->
'enc_CirculationSignature'(element(2,Val), [<<48>>]);
Else ->
exit({error,{asn1,{invalid_choice_type,Else}}})
end,
encode_tags(TagIn, EncBytes, EncLen).
dec_Checkmark(Tlv) ->
dec_Checkmark(Tlv, []).
dec_Checkmark(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
%% 'simple'
{5, V1} ->
{simple, decode_null(V1, [])};
%% 'timestamped'
{24, V1} ->
{timestamped, begin
binary_to_list(decode_restricted_string(V1, []))
end
};
%% 'signed'
{16, V1} ->
{signed, 'dec_CirculationSignature'(V1, [])};
Else ->
exit({error,{asn1,{invalid_choice_tag,Else}}})
end
.
%%================================
%% CirculationTime
%%================================
enc_CirculationTime(Val) ->
enc_CirculationTime(Val, [<<24>>]).
enc_CirculationTime(Val, TagIn) ->
encode_restricted_string(Val, TagIn).
dec_CirculationTime(Tlv) ->
dec_CirculationTime(Tlv, [24]).
dec_CirculationTime(Tlv, TagIn) ->
begin
binary_to_list(decode_restricted_string(Tlv, TagIn))
end
.
%%================================
%% CirculationSignature
%%================================
enc_CirculationSignature(Val) ->
enc_CirculationSignature(Val, [<<48>>]).
enc_CirculationSignature(Val, TagIn) ->
{_,Cindex1,Cindex2,Cindex3} = Val,
%%-------------------------------------------------
%% attribute toBeSigned(1) with type SEQUENCE
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'enc_CirculationSignature_toBeSigned'(Cindex1, [<<48>>]),
%%-------------------------------------------------
%% attribute algorithmIdentifier(2) External AuthenticationFramework:AlgorithmIdentifier
%%-------------------------------------------------
{EncBytes2,EncLen2} = 'AuthenticationFramework':'enc_AlgorithmIdentifier'(Cindex2, [<<48>>]),
%%-------------------------------------------------
%% attribute encrypted(3) with type BIT STRING
%%-------------------------------------------------
{EncBytes3,EncLen3} = encode_unnamed_bit_string(Cindex3, [<<3>>]),
BytesSoFar = [EncBytes1, EncBytes2, EncBytes3],
LenSoFar = EncLen1 + EncLen2 + EncLen3,
encode_tags(TagIn, BytesSoFar, LenSoFar).
%%================================
%% CirculationSignature_toBeSigned
%%================================
enc_CirculationSignature_toBeSigned(Val, TagIn) ->
{_,Cindex1,Cindex2,Cindex3} = Val,
%%-------------------------------------------------
%% attribute algorithm-identifier(1) External IPMSHeadingExtensions:CirculationSignatureAlgorithmIdentifier
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'enc_CirculationSignatureAlgorithmIdentifier'(Cindex1, [<<48>>]),
%%-------------------------------------------------
%% attribute this-IPM(2) External IPMSInformationObjects:ThisIPMField
%%-------------------------------------------------
{EncBytes2,EncLen2} = 'IPMSInformationObjects':'enc_ThisIPMField'(Cindex2, [<<107>>]),
%%-------------------------------------------------
%% attribute timestamp(3) with type GeneralizedTime
%%-------------------------------------------------
{EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<24>>]),
BytesSoFar = [EncBytes1, EncBytes2, EncBytes3],
LenSoFar = EncLen1 + EncLen2 + EncLen3,
encode_tags(TagIn, BytesSoFar, LenSoFar).
dec_CirculationSignature(Tlv) ->
dec_CirculationSignature(Tlv, [16]).
dec_CirculationSignature(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
%%-------------------------------------------------
%% attribute toBeSigned(1) with type SEQUENCE
%%-------------------------------------------------
[V1|Tlv2] = Tlv1,
Term1 = 'dec_CirculationSignature_toBeSigned'(V1, [16]),
%%-------------------------------------------------
%% attribute algorithmIdentifier(2) External AuthenticationFramework:AlgorithmIdentifier
%%-------------------------------------------------
[V2|Tlv3] = Tlv2,
Term2 = 'AuthenticationFramework':'dec_AlgorithmIdentifier'(V2, [16]),
%%-------------------------------------------------
%% attribute encrypted(3) with type BIT STRING
%%-------------------------------------------------
[V3|Tlv4] = Tlv3,
Term3 = decode_native_bit_string(V3, [3]),
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'CirculationSignature',Term1,Term2,Term3},
Res1.
'dec_CirculationSignature_toBeSigned'(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
%%-------------------------------------------------
%% attribute algorithm-identifier(1) External IPMSHeadingExtensions:CirculationSignatureAlgorithmIdentifier
%%-------------------------------------------------
[V1|Tlv2] = Tlv1,
Term1 = 'dec_CirculationSignatureAlgorithmIdentifier'(V1, [16]),
%%-------------------------------------------------
%% attribute this-IPM(2) External IPMSInformationObjects:ThisIPMField
%%-------------------------------------------------
[V2|Tlv3] = Tlv2,
Term2 = 'IPMSInformationObjects':'dec_ThisIPMField'(V2, [65547]),
%%-------------------------------------------------
%% attribute timestamp(3) with type GeneralizedTime
%%-------------------------------------------------
[V3|Tlv4] = Tlv3,
Term3 = begin
binary_to_list(decode_restricted_string(V3, [24]))
end
,
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'CirculationSignature_toBeSigned',Term1,Term2,Term3},
Res1.
%%================================
%% CirculationSignatureAlgorithmIdentifier
%%================================
enc_CirculationSignatureAlgorithmIdentifier(Val) ->
enc_CirculationSignatureAlgorithmIdentifier(Val, [<<48>>]).
enc_CirculationSignatureAlgorithmIdentifier(Val, TagIn) ->
'AuthenticationFramework':enc_AlgorithmIdentifier(Val, TagIn).
dec_CirculationSignatureAlgorithmIdentifier(Tlv) ->
dec_CirculationSignatureAlgorithmIdentifier(Tlv, [16]).
dec_CirculationSignatureAlgorithmIdentifier(Tlv, TagIn) ->
'AuthenticationFramework':'dec_AlgorithmIdentifier'(Tlv, TagIn).
%%================================
%% DistributionCodes
%%================================
enc_DistributionCodes(Val) ->
enc_DistributionCodes(Val, [<<48>>]).
enc_DistributionCodes(Val, TagIn) ->
{EncBytes,EncLen} = 'enc_DistributionCodes_components'(Val,[],0),
encode_tags(TagIn, EncBytes, EncLen).
'enc_DistributionCodes_components'([], AccBytes, AccLen) ->
{lists:reverse(AccBytes),AccLen};
'enc_DistributionCodes_components'([H|T],AccBytes, AccLen) ->
{EncBytes,EncLen} = 'enc_DistributionCode'(H, [<<48>>]),
'enc_DistributionCodes_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
dec_DistributionCodes(Tlv) ->
dec_DistributionCodes(Tlv, [16]).
dec_DistributionCodes(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
['dec_DistributionCode'(V1, [16]) || V1 <- Tlv1].
%%================================
%% DistributionCode
%%================================
enc_DistributionCode(Val) ->
enc_DistributionCode(Val, [<<48>>]).
enc_DistributionCode(Val, TagIn) ->
{_,Cindex1,Cindex2,Cindex3} = Val,
%%-------------------------------------------------
%% attribute oid-code(1) with type OBJECT IDENTIFIER OPTIONAL
%%-------------------------------------------------
{EncBytes1,EncLen1} = case Cindex1 of
asn1_NOVALUE -> {<<>>,0};
_ ->
encode_object_identifier(Cindex1, [<<6>>])
end,
%%-------------------------------------------------
%% attribute alphanumeric-code(2) External IPMSHeadingExtensions:AlphaCode OPTIONAL
%%-------------------------------------------------
{EncBytes2,EncLen2} = case Cindex2 of
asn1_NOVALUE -> {<<>>,0};
_ ->
'enc_AlphaCode'(Cindex2, [<<49>>])
end,
%%-------------------------------------------------
%% attribute or-descriptor(3) External IPMSInformationObjects:ORDescriptor OPTIONAL
%%-------------------------------------------------
{EncBytes3,EncLen3} = case Cindex3 of
asn1_NOVALUE -> {<<>>,0};
_ ->
'IPMSInformationObjects':'enc_ORDescriptor'(Cindex3, [<<160>>])
end,
BytesSoFar = [EncBytes1, EncBytes2, EncBytes3],
LenSoFar = EncLen1 + EncLen2 + EncLen3,
encode_tags(TagIn, BytesSoFar, LenSoFar).
dec_DistributionCode(Tlv) ->
dec_DistributionCode(Tlv, [16]).
dec_DistributionCode(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
%%-------------------------------------------------
%% attribute oid-code(1) with type OBJECT IDENTIFIER OPTIONAL
%%-------------------------------------------------
{Term1,Tlv2} = case Tlv1 of
[{6,V1}|TempTlv2] ->
{decode_object_identifier(V1, []), TempTlv2};
_ ->
{ asn1_NOVALUE, Tlv1}
end,
%%-------------------------------------------------
%% attribute alphanumeric-code(2) External IPMSHeadingExtensions:AlphaCode OPTIONAL
%%-------------------------------------------------
{Term2,Tlv3} = case Tlv2 of
[{17,V2}|TempTlv3] ->
{'dec_AlphaCode'(V2, []), TempTlv3};
_ ->
{ asn1_NOVALUE, Tlv2}
end,
%%-------------------------------------------------
%% attribute or-descriptor(3) External IPMSInformationObjects:ORDescriptor OPTIONAL
%%-------------------------------------------------
{Term3,Tlv4} = case Tlv3 of
[{131072,V3}|TempTlv4] ->
{'IPMSInformationObjects':'dec_ORDescriptor'(V3, []), TempTlv4};
_ ->
{ asn1_NOVALUE, Tlv3}
end,
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'DistributionCode',Term1,Term2,Term3},
Res1.
%%================================
%% AlphaCode
%%================================
enc_AlphaCode(Val) ->
enc_AlphaCode(Val, [<<49>>]).
enc_AlphaCode(Val, TagIn) ->
{_,Cindex1,Cindex2} = Val,
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'enc_AlphaCode_character-encoding'(Cindex1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{EncBytes2,EncLen2} = case Cindex2 of
asn1_NOVALUE -> {<<>>,0};
_ ->
encode_restricted_string(Cindex2, [<<19>>])
end,
BytesSoFar = [EncBytes1, EncBytes2],
LenSoFar = EncLen1 + EncLen2,
encode_tags(TagIn, BytesSoFar, LenSoFar).
%%================================
%% AlphaCode_character-encoding
%%================================
'enc_AlphaCode_character-encoding'(Val, TagIn) ->
{EncBytes,EncLen} = case element(1,Val) of
'two-octets' ->
encode_BMP_string(element(2,Val), [<<30>>]);
'four-octets' ->
encode_universal_string(element(2,Val), [<<28>>]);
Else ->
exit({error,{asn1,{invalid_choice_type,Else}}})
end,
encode_tags(TagIn, EncBytes, EncLen).
dec_AlphaCode(Tlv) ->
dec_AlphaCode(Tlv, [17]).
dec_AlphaCode(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
SetFun = fun(FunTlv) ->
case FunTlv of
%character-encoding
TTlv = {30,_} ->
{1, TTlv};
TTlv = {28,_} ->
{1, TTlv};
%iso-639-language-code
TTlv = {19,_} ->
{2, TTlv};
Else ->
{3, Else}
end
end,
PositionList = [SetFun(TempTlv)|| TempTlv <- Tlv1],
Tlv2 = [Stlv || {_,Stlv} <- lists:sort(PositionList)],
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
[V1|Tlv3] = Tlv2,
Term1 = 'dec_AlphaCode_character-encoding'(V1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{Term2,Tlv4} = case Tlv3 of
[{19,V2}|TempTlv4] ->
{begin
Val1 = decode_restricted_string(V2, []),
C1 = byte_size(Val1),
if 2 =< C1, C1 =< 5 ->
binary_to_list(Val1);
true ->
exit({error,{asn1,bad_range}})
end
end, TempTlv4};
_ ->
{ asn1_NOVALUE, Tlv3}
end,
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'AlphaCode',Term1,Term2},
Res1.
'dec_AlphaCode_character-encoding'(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
%% 'two-octets'
{30, V1} ->
{'two-octets', begin
Val1 = decode_BMP_string(V1, []),
C1 = length(Val1),
if 1 =< C1, C1 =< 16 ->
Val1;
true ->
exit({error,{asn1,bad_range}})
end
end};
%% 'four-octets'
{28, V1} ->
{'four-octets', begin
Val2 = decode_universal_string(V1, []),
C2 = length(Val2),
if 1 =< C2, C2 =< 16 ->
Val2;
true ->
exit({error,{asn1,bad_range}})
end
end};
Else ->
exit({error,{asn1,{invalid_choice_tag,Else}}})
end
.
%%================================
%% ExtendedSubject
%%================================
enc_ExtendedSubject(Val) ->
enc_ExtendedSubject(Val, [<<49>>]).
enc_ExtendedSubject(Val, TagIn) ->
{_,Cindex1,Cindex2} = Val,
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'enc_ExtendedSubject_character-encoding'(Cindex1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{EncBytes2,EncLen2} = case Cindex2 of
asn1_NOVALUE -> {<<>>,0};
_ ->
encode_restricted_string(Cindex2, [<<19>>])
end,
BytesSoFar = [EncBytes1, EncBytes2],
LenSoFar = EncLen1 + EncLen2,
encode_tags(TagIn, BytesSoFar, LenSoFar).
%%================================
%% ExtendedSubject_character-encoding
%%================================
'enc_ExtendedSubject_character-encoding'(Val, TagIn) ->
{EncBytes,EncLen} = case element(1,Val) of
'two-octets' ->
encode_BMP_string(element(2,Val), [<<30>>]);
'four-octets' ->
encode_universal_string(element(2,Val), [<<28>>]);
Else ->
exit({error,{asn1,{invalid_choice_type,Else}}})
end,
encode_tags(TagIn, EncBytes, EncLen).
dec_ExtendedSubject(Tlv) ->
dec_ExtendedSubject(Tlv, [17]).
dec_ExtendedSubject(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
SetFun = fun(FunTlv) ->
case FunTlv of
%character-encoding
TTlv = {30,_} ->
{1, TTlv};
TTlv = {28,_} ->
{1, TTlv};
%iso-639-language-code
TTlv = {19,_} ->
{2, TTlv};
Else ->
{3, Else}
end
end,
PositionList = [SetFun(TempTlv)|| TempTlv <- Tlv1],
Tlv2 = [Stlv || {_,Stlv} <- lists:sort(PositionList)],
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
[V1|Tlv3] = Tlv2,
Term1 = 'dec_ExtendedSubject_character-encoding'(V1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{Term2,Tlv4} = case Tlv3 of
[{19,V2}|TempTlv4] ->
{begin
Val1 = decode_restricted_string(V2, []),
C1 = byte_size(Val1),
if 2 =< C1, C1 =< 5 ->
binary_to_list(Val1);
true ->
exit({error,{asn1,bad_range}})
end
end, TempTlv4};
_ ->
{ asn1_NOVALUE, Tlv3}
end,
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'ExtendedSubject',Term1,Term2},
Res1.
'dec_ExtendedSubject_character-encoding'(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
%% 'two-octets'
{30, V1} ->
{'two-octets', begin
Val1 = decode_BMP_string(V1, []),
C1 = length(Val1),
if 1 =< C1, C1 =< 256 ->
Val1;
true ->
exit({error,{asn1,bad_range}})
end
end};
%% 'four-octets'
{28, V1} ->
{'four-octets', begin
Val2 = decode_universal_string(V1, []),
C2 = length(Val2),
if 1 =< C2, C2 =< 256 ->
Val2;
true ->
exit({error,{asn1,bad_range}})
end
end};
Else ->
exit({error,{asn1,{invalid_choice_tag,Else}}})
end
.
%%================================
%% InformationCategories
%%================================
enc_InformationCategories(Val) ->
enc_InformationCategories(Val, [<<48>>]).
enc_InformationCategories(Val, TagIn) ->
{EncBytes,EncLen} = 'enc_InformationCategories_components'(Val,[],0),
encode_tags(TagIn, EncBytes, EncLen).
'enc_InformationCategories_components'([], AccBytes, AccLen) ->
{lists:reverse(AccBytes),AccLen};
'enc_InformationCategories_components'([H|T],AccBytes, AccLen) ->
{EncBytes,EncLen} = 'enc_InformationCategory'(H, [<<48>>]),
'enc_InformationCategories_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
dec_InformationCategories(Tlv) ->
dec_InformationCategories(Tlv, [16]).
dec_InformationCategories(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
['dec_InformationCategory'(V1, [16]) || V1 <- Tlv1].
%%================================
%% InformationCategory
%%================================
enc_InformationCategory(Val) ->
enc_InformationCategory(Val, [<<48>>]).
enc_InformationCategory(Val, TagIn) ->
{_,Cindex1,Cindex2} = Val,
%%-------------------------------------------------
%% attribute reference(1) with type OBJECT IDENTIFIER OPTIONAL
%%-------------------------------------------------
{EncBytes1,EncLen1} = case Cindex1 of
asn1_NOVALUE -> {<<>>,0};
_ ->
encode_object_identifier(Cindex1, [<<128>>])
end,
%%-------------------------------------------------
%% attribute description(2) External IPMSHeadingExtensions:DescriptionString OPTIONAL
%%-------------------------------------------------
{EncBytes2,EncLen2} = case Cindex2 of
asn1_NOVALUE -> {<<>>,0};
_ ->
'enc_DescriptionString'(Cindex2, [<<161>>])
end,
BytesSoFar = [EncBytes1, EncBytes2],
LenSoFar = EncLen1 + EncLen2,
encode_tags(TagIn, BytesSoFar, LenSoFar).
dec_InformationCategory(Tlv) ->
dec_InformationCategory(Tlv, [16]).
dec_InformationCategory(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
%%-------------------------------------------------
%% attribute reference(1) with type OBJECT IDENTIFIER OPTIONAL
%%-------------------------------------------------
{Term1,Tlv2} = case Tlv1 of
[{131072,V1}|TempTlv2] ->
{decode_object_identifier(V1, []), TempTlv2};
_ ->
{ asn1_NOVALUE, Tlv1}
end,
%%-------------------------------------------------
%% attribute description(2) External IPMSHeadingExtensions:DescriptionString OPTIONAL
%%-------------------------------------------------
{Term2,Tlv3} = case Tlv2 of
[{131073,V2}|TempTlv3] ->
{'dec_DescriptionString'(V2, []), TempTlv3};
_ ->
{ asn1_NOVALUE, Tlv2}
end,
case Tlv3 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed
end,
Res1 = {'InformationCategory',Term1,Term2},
Res1.
%%================================
%% DescriptionString
%%================================
enc_DescriptionString(Val) ->
enc_DescriptionString(Val, [<<49>>]).
enc_DescriptionString(Val, TagIn) ->
{_,Cindex1,Cindex2} = Val,
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'enc_DescriptionString_character-encoding'(Cindex1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{EncBytes2,EncLen2} = case Cindex2 of
asn1_NOVALUE -> {<<>>,0};
_ ->
encode_restricted_string(Cindex2, [<<19>>])
end,
BytesSoFar = [EncBytes1, EncBytes2],
LenSoFar = EncLen1 + EncLen2,
encode_tags(TagIn, BytesSoFar, LenSoFar).
%%================================
%% DescriptionString_character-encoding
%%================================
'enc_DescriptionString_character-encoding'(Val, TagIn) ->
{EncBytes,EncLen} = case element(1,Val) of
'two-octets' ->
encode_BMP_string(element(2,Val), [<<30>>]);
'four-octets' ->
encode_universal_string(element(2,Val), [<<28>>]);
Else ->
exit({error,{asn1,{invalid_choice_type,Else}}})
end,
encode_tags(TagIn, EncBytes, EncLen).
dec_DescriptionString(Tlv) ->
dec_DescriptionString(Tlv, [17]).
dec_DescriptionString(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
SetFun = fun(FunTlv) ->
case FunTlv of
%character-encoding
TTlv = {30,_} ->
{1, TTlv};
TTlv = {28,_} ->
{1, TTlv};
%iso-639-language-code
TTlv = {19,_} ->
{2, TTlv};
Else ->
{3, Else}
end
end,
PositionList = [SetFun(TempTlv)|| TempTlv <- Tlv1],
Tlv2 = [Stlv || {_,Stlv} <- lists:sort(PositionList)],
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
[V1|Tlv3] = Tlv2,
Term1 = 'dec_DescriptionString_character-encoding'(V1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{Term2,Tlv4} = case Tlv3 of
[{19,V2}|TempTlv4] ->
{begin
Val1 = decode_restricted_string(V2, []),
C1 = byte_size(Val1),
if 2 =< C1, C1 =< 5 ->
binary_to_list(Val1);
true ->
exit({error,{asn1,bad_range}})
end
end, TempTlv4};
_ ->
{ asn1_NOVALUE, Tlv3}
end,
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'DescriptionString',Term1,Term2},
Res1.
'dec_DescriptionString_character-encoding'(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
%% 'two-octets'
{30, V1} ->
{'two-octets', begin
Val1 = decode_BMP_string(V1, []),
C1 = length(Val1),
if 1 =< C1, C1 =< 64 ->
Val1;
true ->
exit({error,{asn1,bad_range}})
end
end};
%% 'four-octets'
{28, V1} ->
{'four-octets', begin
Val2 = decode_universal_string(V1, []),
C2 = length(Val2),
if 1 =< C2, C2 =< 64 ->
Val2;
true ->
exit({error,{asn1,bad_range}})
end
end};
Else ->
exit({error,{asn1,{invalid_choice_tag,Else}}})
end
.
%%================================
%% ManualHandlingInstructions
%%================================
enc_ManualHandlingInstructions(Val) ->
enc_ManualHandlingInstructions(Val, [<<48>>]).
enc_ManualHandlingInstructions(Val, TagIn) ->
{EncBytes,EncLen} = 'enc_ManualHandlingInstructions_components'(Val,[],0),
encode_tags(TagIn, EncBytes, EncLen).
'enc_ManualHandlingInstructions_components'([], AccBytes, AccLen) ->
{lists:reverse(AccBytes),AccLen};
'enc_ManualHandlingInstructions_components'([H|T],AccBytes, AccLen) ->
{EncBytes,EncLen} = 'enc_ManualHandlingInstruction'(H, [<<49>>]),
'enc_ManualHandlingInstructions_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
dec_ManualHandlingInstructions(Tlv) ->
dec_ManualHandlingInstructions(Tlv, [16]).
dec_ManualHandlingInstructions(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
['dec_ManualHandlingInstruction'(V1, [17]) || V1 <- Tlv1].
%%================================
%% ManualHandlingInstruction
%%================================
enc_ManualHandlingInstruction(Val) ->
enc_ManualHandlingInstruction(Val, [<<49>>]).
enc_ManualHandlingInstruction(Val, TagIn) ->
{_,Cindex1,Cindex2} = Val,
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'enc_ManualHandlingInstruction_character-encoding'(Cindex1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{EncBytes2,EncLen2} = case Cindex2 of
asn1_NOVALUE -> {<<>>,0};
_ ->
encode_restricted_string(Cindex2, [<<19>>])
end,
BytesSoFar = [EncBytes1, EncBytes2],
LenSoFar = EncLen1 + EncLen2,
encode_tags(TagIn, BytesSoFar, LenSoFar).
%%================================
%% ManualHandlingInstruction_character-encoding
%%================================
'enc_ManualHandlingInstruction_character-encoding'(Val, TagIn) ->
{EncBytes,EncLen} = case element(1,Val) of
'two-octets' ->
encode_BMP_string(element(2,Val), [<<30>>]);
'four-octets' ->
encode_universal_string(element(2,Val), [<<28>>]);
Else ->
exit({error,{asn1,{invalid_choice_type,Else}}})
end,
encode_tags(TagIn, EncBytes, EncLen).
dec_ManualHandlingInstruction(Tlv) ->
dec_ManualHandlingInstruction(Tlv, [17]).
dec_ManualHandlingInstruction(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
SetFun = fun(FunTlv) ->
case FunTlv of
%character-encoding
TTlv = {30,_} ->
{1, TTlv};
TTlv = {28,_} ->
{1, TTlv};
%iso-639-language-code
TTlv = {19,_} ->
{2, TTlv};
Else ->
{3, Else}
end
end,
PositionList = [SetFun(TempTlv)|| TempTlv <- Tlv1],
Tlv2 = [Stlv || {_,Stlv} <- lists:sort(PositionList)],
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
[V1|Tlv3] = Tlv2,
Term1 = 'dec_ManualHandlingInstruction_character-encoding'(V1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{Term2,Tlv4} = case Tlv3 of
[{19,V2}|TempTlv4] ->
{begin
Val1 = decode_restricted_string(V2, []),
C1 = byte_size(Val1),
if 2 =< C1, C1 =< 5 ->
binary_to_list(Val1);
true ->
exit({error,{asn1,bad_range}})
end
end, TempTlv4};
_ ->
{ asn1_NOVALUE, Tlv3}
end,
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'ManualHandlingInstruction',Term1,Term2},
Res1.
'dec_ManualHandlingInstruction_character-encoding'(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
%% 'two-octets'
{30, V1} ->
{'two-octets', begin
Val1 = decode_BMP_string(V1, []),
C1 = length(Val1),
if 1 =< C1, C1 =< 128 ->
Val1;
true ->
exit({error,{asn1,bad_range}})
end
end};
%% 'four-octets'
{28, V1} ->
{'four-octets', begin
Val2 = decode_universal_string(V1, []),
C2 = length(Val2),
if 1 =< C2, C2 =< 128 ->
Val2;
true ->
exit({error,{asn1,bad_range}})
end
end};
Else ->
exit({error,{asn1,{invalid_choice_tag,Else}}})
end
.
%%================================
%% OriginatorsReference
%%================================
enc_OriginatorsReference(Val) ->
enc_OriginatorsReference(Val, [<<49>>]).
enc_OriginatorsReference(Val, TagIn) ->
{_,Cindex1,Cindex2} = Val,
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
{EncBytes1,EncLen1} = 'enc_OriginatorsReference_character-encoding'(Cindex1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{EncBytes2,EncLen2} = case Cindex2 of
asn1_NOVALUE -> {<<>>,0};
_ ->
encode_restricted_string(Cindex2, [<<19>>])
end,
BytesSoFar = [EncBytes1, EncBytes2],
LenSoFar = EncLen1 + EncLen2,
encode_tags(TagIn, BytesSoFar, LenSoFar).
%%================================
%% OriginatorsReference_character-encoding
%%================================
'enc_OriginatorsReference_character-encoding'(Val, TagIn) ->
{EncBytes,EncLen} = case element(1,Val) of
'two-octets' ->
encode_BMP_string(element(2,Val), [<<30>>]);
'four-octets' ->
encode_universal_string(element(2,Val), [<<28>>]);
Else ->
exit({error,{asn1,{invalid_choice_type,Else}}})
end,
encode_tags(TagIn, EncBytes, EncLen).
dec_OriginatorsReference(Tlv) ->
dec_OriginatorsReference(Tlv, [17]).
dec_OriginatorsReference(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
SetFun = fun(FunTlv) ->
case FunTlv of
%character-encoding
TTlv = {30,_} ->
{1, TTlv};
TTlv = {28,_} ->
{1, TTlv};
%iso-639-language-code
TTlv = {19,_} ->
{2, TTlv};
Else ->
{3, Else}
end
end,
PositionList = [SetFun(TempTlv)|| TempTlv <- Tlv1],
Tlv2 = [Stlv || {_,Stlv} <- lists:sort(PositionList)],
%%-------------------------------------------------
%% attribute character-encoding(1) with type CHOICE
%%-------------------------------------------------
[V1|Tlv3] = Tlv2,
Term1 = 'dec_OriginatorsReference_character-encoding'(V1, []),
%%-------------------------------------------------
%% attribute iso-639-language-code(2) with type PrintableString OPTIONAL
%%-------------------------------------------------
{Term2,Tlv4} = case Tlv3 of
[{19,V2}|TempTlv4] ->
{begin
Val1 = decode_restricted_string(V2, []),
C1 = byte_size(Val1),
if 2 =< C1, C1 =< 5 ->
binary_to_list(Val1);
true ->
exit({error,{asn1,bad_range}})
end
end, TempTlv4};
_ ->
{ asn1_NOVALUE, Tlv3}
end,
case Tlv4 of
[] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed
end,
Res1 = {'OriginatorsReference',Term1,Term2},
Res1.
'dec_OriginatorsReference_character-encoding'(Tlv, TagIn) ->
Tlv1 = match_tags(Tlv, TagIn),
case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of
%% 'two-octets'
{30, V1} ->
{'two-octets', begin
Val1 = decode_BMP_string(V1, []),
C1 = length(Val1),
if 1 =< C1, C1 =< 64 ->
Val1;
true ->
exit({error,{asn1,bad_range}})
end
end};
%% 'four-octets'
{28, V1} ->
{'four-octets', begin
Val2 = decode_universal_string(V1, []),
C2 = length(Val2),
if 1 =< C2, C2 =< 64 ->
Val2;
true ->
exit({error,{asn1,bad_range}})
end
end};
Else ->
exit({error,{asn1,{invalid_choice_tag,Else}}})
end
.
%%================================
%% PrecedencePolicyIdentifier
%%================================
enc_PrecedencePolicyIdentifier(Val) ->
enc_PrecedencePolicyIdentifier(Val, [<<6>>]).
enc_PrecedencePolicyIdentifier(Val, TagIn) ->
encode_object_identifier(Val, TagIn).
dec_PrecedencePolicyIdentifier(Tlv) ->
dec_PrecedencePolicyIdentifier(Tlv, [6]).
dec_PrecedencePolicyIdentifier(Tlv, TagIn) ->
decode_object_identifier(Tlv, TagIn).
%%================================
%% Precedence
%%================================
enc_Precedence(Val) ->
enc_Precedence(Val, [<<2>>]).
enc_Precedence(Val, TagIn) ->
encode_integer(Val, TagIn).
dec_Precedence(Tlv) ->
dec_Precedence(Tlv, [2]).
dec_Precedence(Tlv, TagIn) ->
begin
Val1 = decode_integer(Tlv, TagIn),
if 0 =< Val1, Val1 =< 127 ->
Val1;
true ->
exit({error,{asn1,bad_range}})
end
end.
%%================================
%% incomplete-copy
%%================================
'enc_incomplete-copy'('Type', Val, _RestPrimFieldName) ->
enc_IncompleteCopy(Val, [<<5>>]).
'dec_incomplete-copy'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_IncompleteCopy(Tlv, [5]).
tlv_format(Bytes) when is_binary(Bytes) ->
{Tlv,_} = ber_decode_nif(Bytes),
Tlv;
tlv_format(Bytes) ->
Bytes.
%%================================
%% languages
%%================================
enc_languages('Type', Val, _RestPrimFieldName) ->
enc_languages_Type(Val,[<<49>>]).
%%================================
%% languages_Type
%%================================
enc_languages_Type(Val, TagIn) ->
{EncBytes,EncLen} = 'enc_languages_Type_components'(Val,[],0),
encode_tags(TagIn, EncBytes, EncLen).
'enc_languages_Type_components'([], AccBytes, AccLen) ->
{lists:reverse(AccBytes),AccLen};
'enc_languages_Type_components'([H|T],AccBytes, AccLen) ->
{EncBytes,EncLen} = encode_restricted_string(H, [<<19>>]),
'enc_languages_Type_components'(T,[EncBytes|AccBytes], AccLen + EncLen).
dec_languages('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_languages_Type(Tlv,[17]).
'dec_languages_Type'(Tlv, TagIn) ->
%%-------------------------------------------------
%% decode tag and length
%%-------------------------------------------------
Tlv1 = match_tags(Tlv, TagIn),
[begin
Val1 = decode_restricted_string(V1, [19]),
C1 = byte_size(Val1),
if 2 =< C1, C1 =< 5 ->
binary_to_list(Val1);
true ->
exit({error,{asn1,bad_range}})
end
end || V1 <- Tlv1].
%%================================
%% auto-submitted
%%================================
'enc_auto-submitted'('Type', Val, _RestPrimFieldName) ->
enc_AutoSubmitted(Val, [<<10>>]).
'dec_auto-submitted'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_AutoSubmitted(Tlv, [10]).
%%================================
%% body-part-signatures
%%================================
'enc_body-part-signatures'('Type', Val, _RestPrimFieldName) ->
enc_BodyPartSignatures(Val, [<<49>>]).
'dec_body-part-signatures'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_BodyPartSignatures(Tlv, [17]).
%%================================
%% ipm-security-label
%%================================
'enc_ipm-security-label'('Type', Val, _RestPrimFieldName) ->
enc_IPMSecurityLabel(Val, [<<48>>]).
'dec_ipm-security-label'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_IPMSecurityLabel(Tlv, [16]).
%%================================
%% authorization-time
%%================================
'enc_authorization-time'('Type', Val, _RestPrimFieldName) ->
enc_AuthorizationTime(Val, [<<24>>]).
'dec_authorization-time'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_AuthorizationTime(Tlv, [24]).
%%================================
%% circulation-list-recipients
%%================================
'enc_circulation-list-recipients'('Type', Val, _RestPrimFieldName) ->
enc_CirculationList(Val, [<<48>>]).
'dec_circulation-list-recipients'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_CirculationList(Tlv, [16]).
%%================================
%% circulation-list-indicator
%%================================
'enc_circulation-list-indicator'('Type', Val, _RestPrimFieldName) ->
encode_null(Val, [<<5>>]).
'dec_circulation-list-indicator'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
decode_null(Tlv, [5]).
%%================================
%% distribution-codes
%%================================
'enc_distribution-codes'('Type', Val, _RestPrimFieldName) ->
enc_DistributionCodes(Val, [<<48>>]).
'dec_distribution-codes'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_DistributionCodes(Tlv, [16]).
%%================================
%% extended-subject
%%================================
'enc_extended-subject'('Type', Val, _RestPrimFieldName) ->
enc_ExtendedSubject(Val, [<<49>>]).
'dec_extended-subject'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_ExtendedSubject(Tlv, [17]).
%%================================
%% information-category
%%================================
'enc_information-category'('Type', Val, _RestPrimFieldName) ->
enc_InformationCategories(Val, [<<48>>]).
'dec_information-category'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_InformationCategories(Tlv, [16]).
%%================================
%% manual-handling-instructions
%%================================
'enc_manual-handling-instructions'('Type', Val, _RestPrimFieldName) ->
enc_ManualHandlingInstructions(Val, [<<48>>]).
'dec_manual-handling-instructions'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_ManualHandlingInstructions(Tlv, [16]).
%%================================
%% originators-reference
%%================================
'enc_originators-reference'('Type', Val, _RestPrimFieldName) ->
enc_OriginatorsReference(Val, [<<49>>]).
'dec_originators-reference'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_OriginatorsReference(Tlv, [17]).
%%================================
%% precedence-policy-identifier
%%================================
'enc_precedence-policy-identifier'('Type', Val, _RestPrimFieldName) ->
enc_PrecedencePolicyIdentifier(Val, [<<6>>]).
'dec_precedence-policy-identifier'('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_PrecedencePolicyIdentifier(Tlv, [6]).
%%================================
%% precedence
%%================================
enc_precedence('Type', Val, _RestPrimFieldName) ->
enc_Precedence(Val, [<<2>>]).
dec_precedence('Type', Bytes,_) ->
Tlv = tlv_format(Bytes),
dec_Precedence(Tlv, [2]).
%%%
%%% Run-time functions.
%%%
'dialyzer-suppressions'(Arg) ->
ok.
ber_decode_nif(B) ->
asn1rt_nif:decode_ber_tlv(B).
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, <<Unused,Bits/binary>>} | 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, <<Unused,Bits/binary>>} | 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(<<H,T/binary>>, Av, Al) ->
dec_subidentifiers(T, 0, [Av bsl 7 + H | Al]).
decode_BMP_string(Buffer, Tags) ->
Bin = match_and_collect(Buffer, Tags),
mk_BMP_string(binary_to_list(Bin)).
decode_integer(Tlv, TagIn) ->
Bin = match_tags(Tlv, TagIn),
Len = byte_size(Bin),
<<Int:Len/signed-unit:8>> = Bin,
Int.
decode_native_bit_string(Buffer, Tags) ->
case match_and_collect(Buffer, Tags) of
<<0>> ->
<<>>;
<<Unused,Bits/binary>> ->
Size = bit_size(Bits) - Unused,
<<Val:Size/bitstring,_:Unused/bitstring>> = Bits,
Val
end.
decode_null(Tlv, Tags) ->
Val = match_tags(Tlv, Tags),
case Val of
<<>> ->
'NULL';
_ ->
exit({error, {asn1, {decode_null, 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_restricted_string(Tlv, TagsIn) ->
match_and_collect(Tlv, TagsIn).
decode_universal_string(Buffer, Tags) ->
Bin = match_and_collect(Buffer, Tags),
mk_universal_string(binary_to_list(Bin)).
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_BMP_string(BMPString, TagIn) ->
OctetList = mk_BMP_list(BMPString),
encode_tags(TagIn, OctetList, length(OctetList)).
encode_integer(Val) ->
Bytes =
if
Val >= 0 ->
encode_integer_pos(Val, []);
true ->
encode_integer_neg(Val, [])
end,
{Bytes, length(Bytes)}.
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_null(_Val, TagIn) ->
encode_tags(TagIn, [], 0).
encode_object_identifier(Val, TagIn) ->
encode_tags(TagIn, e_object_identifier(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_universal_string(Universal, TagIn) ->
OctetList = mk_uni_list(Universal),
encode_tags(TagIn, OctetList, length(OctetList)).
encode_unnamed_bit_string(Bits, TagIn) ->
Unused = (8 - bit_size(Bits) band 7) band 7,
Bin = <<Unused,Bits/bitstring,0:Unused>>,
encode_tags(TagIn, Bin, byte_size(Bin)).
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_BMP_list(In) ->
mk_BMP_list(In, []).
mk_BMP_list([], List) ->
lists:reverse(List);
mk_BMP_list([{0, 0, C, D} | T], List) ->
mk_BMP_list(T, [D, C | List]);
mk_BMP_list([H | T], List) ->
mk_BMP_list(T, [H, 0 | List]).
mk_BMP_string(In) ->
mk_BMP_string(In, []).
mk_BMP_string([], US) ->
lists:reverse(US);
mk_BMP_string([0, B | T], US) ->
mk_BMP_string(T, [B | US]);
mk_BMP_string([C, D | T], US) ->
mk_BMP_string(T, [{0, 0, C, D} | US]).
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).
mk_uni_list(In) ->
mk_uni_list(In, []).
mk_uni_list([], List) ->
lists:reverse(List);
mk_uni_list([{A, B, C, D} | T], List) ->
mk_uni_list(T, [D, C, B, A | List]);
mk_uni_list([H | T], List) ->
mk_uni_list(T, [H, 0, 0, 0 | List]).
mk_universal_string(In) ->
mk_universal_string(In, []).
mk_universal_string([], Acc) ->
lists:reverse(Acc);
mk_universal_string([0, 0, 0, D | T], Acc) ->
mk_universal_string(T, [D | Acc]);
mk_universal_string([A, B, C, D | T], Acc) ->
mk_universal_string(T, [{A, B, C, D} | Acc]).