%% Generated by the Erlang ASN.1 BER compiler. Version: 5.0.13 %% Purpose: Encoding and decoding of the types in KEP. -module('KEP'). -compile(nowarn_unused_vars). -dialyzer(no_improper_lists). -dialyzer(no_match). -include("KEP.hrl"). -asn1_info([{vsn,'5.0.13'}, {module,'KEP'}, {options,[warnings,ber,errors, {cwd,"/home/maxim/depot/synrc/ca/priv/kep"}, {outdir,"/home/maxim/depot/synrc/ca/priv/kep"}, {i,"."}, {i,"/home/maxim/depot/synrc/ca/priv/kep"}]}]). -export([encoding_rule/0,maps/0,bit_string_format/0, legacy_erlang_types/0]). -export(['dialyzer-suppressions'/1]). -export([ decode_object_identifier/2, enc_ContentInfo/2, enc_UnknownInfo/2, enc_CrlValidatedID/2, enc_OtherHash/2, enc_OcspListID/2, enc_OcspResponsesID/2, enc_OtherRevRefs/2, enc_OcspIdentifier/2, enc_OtherRevRefType/2, enc_ContentType/2, enc_CMSVersion/2, enc_GeneralNames/2, enc_GeneralName/2, enc_TSAPolicyId/2, enc_SignatureAlgorithmIdentifier/2, enc_KeyIdentifier/2, enc_SubjectKeyIdentifier/2, enc_RevocationInfoChoices/2, enc_SignerInfos/2, enc_CertificateSet/2, enc_SignedData/2, enc_EncapsulatedContentInfo/2, enc_SignerInfo/2, enc_SignerIdentifier/2, enc_IssuerAndSerialNumber/2, enc_Hash/2, enc_IssuerSerial/2, enc_ESSCertIDv2/2, enc_OtherHashValue/2, enc_OtherHashAlgAndValue/2, enc_SPuri/2, enc_SigPolicyId/2, enc_SigPolicyHash/2, enc_SigPolicyQualifierId/2, enc_SignaturePolicyIdentifier/2, enc_SigPolicyQualifierInfo/2, enc_SignaturePolicyId/2, enc_DigestAlgorithmIdentifiers/2, enc_DigestAlgorithmIdentifier/2, enc_CertificateSerialNumber/2, enc_SignedAttributes/2, enc_UnsignedAttributes/2, enc_Attribute/2, enc_AttributeValue/2, enc_MessageDigest/2, enc_SigningCertificateV2/2, enc_SignaturePolicyImplied/2, enc_DisplayText/2, enc_CrlOcspRef/2, enc_CrlIdentifier/2, enc_BasicOCSPResponse/2, enc_ResponseData/2, enc_ResponderID/2, enc_KeyHash/2, enc_CertID/2, enc_CertStatus/2, enc_RevokedInfo/2, enc_SingleResponse/2, enc_RevocationValues/2, enc_OtherRevValType/2, enc_OtherRevVals/2, enc_CRLListID/2, enc_MessageImprint/2, enc_TimeStampReq/2, 'enc_INSTANCE OF'/2 ]). -export([ dec_ContentInfo/2, dec_UnknownInfo/2, dec_CrlValidatedID/2, dec_OtherHash/2, dec_OcspListID/2, dec_OcspResponsesID/2, dec_OtherRevRefs/2, dec_OcspIdentifier/2, dec_OtherRevRefType/2, dec_ContentType/2, dec_CMSVersion/2, dec_GeneralNames/2, dec_GeneralName/2, dec_TSAPolicyId/2, dec_SignatureAlgorithmIdentifier/2, dec_KeyIdentifier/2, dec_SubjectKeyIdentifier/2, dec_RevocationInfoChoices/2, dec_SignerInfos/2, dec_CertificateSet/2, dec_SignedData/2, dec_EncapsulatedContentInfo/2, dec_SignerInfo/2, dec_SignerIdentifier/2, dec_IssuerAndSerialNumber/2, dec_Hash/2, dec_IssuerSerial/2, dec_ESSCertIDv2/2, dec_OtherHashValue/2, dec_OtherHashAlgAndValue/2, dec_SPuri/2, dec_SigPolicyId/2, dec_SigPolicyHash/2, dec_SigPolicyQualifierId/2, dec_SignaturePolicyIdentifier/2, dec_SigPolicyQualifierInfo/2, dec_SignaturePolicyId/2, dec_DigestAlgorithmIdentifiers/2, dec_DigestAlgorithmIdentifier/2, dec_CertificateSerialNumber/2, dec_SignedAttributes/2, dec_UnsignedAttributes/2, dec_Attribute/2, dec_AttributeValue/2, dec_MessageDigest/2, dec_SigningCertificateV2/2, dec_SignaturePolicyImplied/2, dec_DisplayText/2, dec_CrlOcspRef/2, dec_CrlIdentifier/2, dec_BasicOCSPResponse/2, dec_ResponseData/2, dec_ResponderID/2, dec_KeyHash/2, dec_CertID/2, dec_CertStatus/2, dec_RevokedInfo/2, dec_SingleResponse/2, dec_RevocationValues/2, dec_OtherRevValType/2, dec_OtherRevVals/2, dec_CRLListID/2, dec_MessageImprint/2, dec_TimeStampReq/2, 'dec_INSTANCE OF'/2 ]). -export([ 'id-data'/0, 'id-signedData'/0, 'id-contentType'/0, 'id-messageDigest'/0, 'id-signingTime'/0, 'id-aa-signTSToken'/0, 'id-aa-ets-sigPolicyId'/0, 'id-aa-ets-ContentTS'/0, 'id-aa-ets-certRefs'/0, 'id-aa-ets-revocationRefs'/0, 'id-aa-ets-certValues'/0, 'id-aa-ets-revoValues'/0, 'id-aa-signingCertV2'/0, 'id-spq-ets-uri'/0, 'id-spq-ets-unotice'/0, gost34311/0 ]). -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('ContentInfo', Data) -> enc_ContentInfo(Data); encode_disp('UnknownInfo', Data) -> enc_UnknownInfo(Data); encode_disp('CrlValidatedID', Data) -> enc_CrlValidatedID(Data); encode_disp('OtherHash', Data) -> enc_OtherHash(Data); encode_disp('OcspListID', Data) -> enc_OcspListID(Data); encode_disp('OcspResponsesID', Data) -> enc_OcspResponsesID(Data); encode_disp('OtherRevRefs', Data) -> enc_OtherRevRefs(Data); encode_disp('OcspIdentifier', Data) -> enc_OcspIdentifier(Data); encode_disp('OtherRevRefType', Data) -> enc_OtherRevRefType(Data); encode_disp('ContentType', Data) -> enc_ContentType(Data); encode_disp('CMSVersion', Data) -> enc_CMSVersion(Data); encode_disp('GeneralNames', Data) -> enc_GeneralNames(Data); encode_disp('GeneralName', Data) -> enc_GeneralName(Data); encode_disp('TSAPolicyId', Data) -> enc_TSAPolicyId(Data); encode_disp('SignatureAlgorithmIdentifier', Data) -> enc_SignatureAlgorithmIdentifier(Data); encode_disp('KeyIdentifier', Data) -> enc_KeyIdentifier(Data); encode_disp('SubjectKeyIdentifier', Data) -> enc_SubjectKeyIdentifier(Data); encode_disp('RevocationInfoChoices', Data) -> enc_RevocationInfoChoices(Data); encode_disp('SignerInfos', Data) -> enc_SignerInfos(Data); encode_disp('CertificateSet', Data) -> enc_CertificateSet(Data); encode_disp('SignedData', Data) -> enc_SignedData(Data); encode_disp('EncapsulatedContentInfo', Data) -> enc_EncapsulatedContentInfo(Data); encode_disp('SignerInfo', Data) -> enc_SignerInfo(Data); encode_disp('SignerIdentifier', Data) -> enc_SignerIdentifier(Data); encode_disp('IssuerAndSerialNumber', Data) -> enc_IssuerAndSerialNumber(Data); encode_disp('Hash', Data) -> enc_Hash(Data); encode_disp('IssuerSerial', Data) -> enc_IssuerSerial(Data); encode_disp('ESSCertIDv2', Data) -> enc_ESSCertIDv2(Data); encode_disp('OtherHashValue', Data) -> enc_OtherHashValue(Data); encode_disp('OtherHashAlgAndValue', Data) -> enc_OtherHashAlgAndValue(Data); encode_disp('SPuri', Data) -> enc_SPuri(Data); encode_disp('SigPolicyId', Data) -> enc_SigPolicyId(Data); encode_disp('SigPolicyHash', Data) -> enc_SigPolicyHash(Data); encode_disp('SigPolicyQualifierId', Data) -> enc_SigPolicyQualifierId(Data); encode_disp('SignaturePolicyIdentifier', Data) -> enc_SignaturePolicyIdentifier(Data); encode_disp('SigPolicyQualifierInfo', Data) -> enc_SigPolicyQualifierInfo(Data); encode_disp('SignaturePolicyId', Data) -> enc_SignaturePolicyId(Data); encode_disp('DigestAlgorithmIdentifiers', Data) -> enc_DigestAlgorithmIdentifiers(Data); encode_disp('DigestAlgorithmIdentifier', Data) -> enc_DigestAlgorithmIdentifier(Data); encode_disp('CertificateSerialNumber', Data) -> enc_CertificateSerialNumber(Data); encode_disp('SignedAttributes', Data) -> enc_SignedAttributes(Data); encode_disp('UnsignedAttributes', Data) -> enc_UnsignedAttributes(Data); encode_disp('Attribute', Data) -> enc_Attribute(Data); encode_disp('AttributeValue', Data) -> enc_AttributeValue(Data); encode_disp('MessageDigest', Data) -> enc_MessageDigest(Data); encode_disp('SigningCertificateV2', Data) -> enc_SigningCertificateV2(Data); encode_disp('SignaturePolicyImplied', Data) -> enc_SignaturePolicyImplied(Data); encode_disp('DisplayText', Data) -> enc_DisplayText(Data); encode_disp('CrlOcspRef', Data) -> enc_CrlOcspRef(Data); encode_disp('CrlIdentifier', Data) -> enc_CrlIdentifier(Data); encode_disp('BasicOCSPResponse', Data) -> enc_BasicOCSPResponse(Data); encode_disp('ResponseData', Data) -> enc_ResponseData(Data); encode_disp('ResponderID', Data) -> enc_ResponderID(Data); encode_disp('KeyHash', Data) -> enc_KeyHash(Data); encode_disp('CertID', Data) -> enc_CertID(Data); encode_disp('CertStatus', Data) -> enc_CertStatus(Data); encode_disp('RevokedInfo', Data) -> enc_RevokedInfo(Data); encode_disp('SingleResponse', Data) -> enc_SingleResponse(Data); encode_disp('RevocationValues', Data) -> enc_RevocationValues(Data); encode_disp('OtherRevValType', Data) -> enc_OtherRevValType(Data); encode_disp('OtherRevVals', Data) -> enc_OtherRevVals(Data); encode_disp('CRLListID', Data) -> enc_CRLListID(Data); encode_disp('MessageImprint', Data) -> enc_MessageImprint(Data); encode_disp('TimeStampReq', Data) -> enc_TimeStampReq(Data); encode_disp('INSTANCE OF', Data) -> 'enc_INSTANCE OF'(Data); encode_disp(Type, _Data) -> exit({error,{asn1,{undefined_type,Type}}}). decode_disp('ContentInfo', Data) -> dec_ContentInfo(Data); decode_disp('UnknownInfo', Data) -> dec_UnknownInfo(Data); decode_disp('CrlValidatedID', Data) -> dec_CrlValidatedID(Data); decode_disp('OtherHash', Data) -> dec_OtherHash(Data); decode_disp('OcspListID', Data) -> dec_OcspListID(Data); decode_disp('OcspResponsesID', Data) -> dec_OcspResponsesID(Data); decode_disp('OtherRevRefs', Data) -> dec_OtherRevRefs(Data); decode_disp('OcspIdentifier', Data) -> dec_OcspIdentifier(Data); decode_disp('OtherRevRefType', Data) -> dec_OtherRevRefType(Data); decode_disp('ContentType', Data) -> dec_ContentType(Data); decode_disp('CMSVersion', Data) -> dec_CMSVersion(Data); decode_disp('GeneralNames', Data) -> dec_GeneralNames(Data); decode_disp('GeneralName', Data) -> dec_GeneralName(Data); decode_disp('TSAPolicyId', Data) -> dec_TSAPolicyId(Data); decode_disp('SignatureAlgorithmIdentifier', Data) -> dec_SignatureAlgorithmIdentifier(Data); decode_disp('KeyIdentifier', Data) -> dec_KeyIdentifier(Data); decode_disp('SubjectKeyIdentifier', Data) -> dec_SubjectKeyIdentifier(Data); decode_disp('RevocationInfoChoices', Data) -> dec_RevocationInfoChoices(Data); decode_disp('SignerInfos', Data) -> dec_SignerInfos(Data); decode_disp('CertificateSet', Data) -> dec_CertificateSet(Data); decode_disp('SignedData', Data) -> dec_SignedData(Data); decode_disp('EncapsulatedContentInfo', Data) -> dec_EncapsulatedContentInfo(Data); decode_disp('SignerInfo', Data) -> dec_SignerInfo(Data); decode_disp('SignerIdentifier', Data) -> dec_SignerIdentifier(Data); decode_disp('IssuerAndSerialNumber', Data) -> dec_IssuerAndSerialNumber(Data); decode_disp('Hash', Data) -> dec_Hash(Data); decode_disp('IssuerSerial', Data) -> dec_IssuerSerial(Data); decode_disp('ESSCertIDv2', Data) -> dec_ESSCertIDv2(Data); decode_disp('OtherHashValue', Data) -> dec_OtherHashValue(Data); decode_disp('OtherHashAlgAndValue', Data) -> dec_OtherHashAlgAndValue(Data); decode_disp('SPuri', Data) -> dec_SPuri(Data); decode_disp('SigPolicyId', Data) -> dec_SigPolicyId(Data); decode_disp('SigPolicyHash', Data) -> dec_SigPolicyHash(Data); decode_disp('SigPolicyQualifierId', Data) -> dec_SigPolicyQualifierId(Data); decode_disp('SignaturePolicyIdentifier', Data) -> dec_SignaturePolicyIdentifier(Data); decode_disp('SigPolicyQualifierInfo', Data) -> dec_SigPolicyQualifierInfo(Data); decode_disp('SignaturePolicyId', Data) -> dec_SignaturePolicyId(Data); decode_disp('DigestAlgorithmIdentifiers', Data) -> dec_DigestAlgorithmIdentifiers(Data); decode_disp('DigestAlgorithmIdentifier', Data) -> dec_DigestAlgorithmIdentifier(Data); decode_disp('CertificateSerialNumber', Data) -> dec_CertificateSerialNumber(Data); decode_disp('SignedAttributes', Data) -> dec_SignedAttributes(Data); decode_disp('UnsignedAttributes', Data) -> dec_UnsignedAttributes(Data); decode_disp('Attribute', Data) -> dec_Attribute(Data); decode_disp('AttributeValue', Data) -> dec_AttributeValue(Data); decode_disp('MessageDigest', Data) -> dec_MessageDigest(Data); decode_disp('SigningCertificateV2', Data) -> dec_SigningCertificateV2(Data); decode_disp('SignaturePolicyImplied', Data) -> dec_SignaturePolicyImplied(Data); decode_disp('DisplayText', Data) -> dec_DisplayText(Data); decode_disp('CrlOcspRef', Data) -> dec_CrlOcspRef(Data); decode_disp('CrlIdentifier', Data) -> dec_CrlIdentifier(Data); decode_disp('BasicOCSPResponse', Data) -> dec_BasicOCSPResponse(Data); decode_disp('ResponseData', Data) -> dec_ResponseData(Data); decode_disp('ResponderID', Data) -> dec_ResponderID(Data); decode_disp('KeyHash', Data) -> dec_KeyHash(Data); decode_disp('CertID', Data) -> dec_CertID(Data); decode_disp('CertStatus', Data) -> dec_CertStatus(Data); decode_disp('RevokedInfo', Data) -> dec_RevokedInfo(Data); decode_disp('SingleResponse', Data) -> dec_SingleResponse(Data); decode_disp('RevocationValues', Data) -> dec_RevocationValues(Data); decode_disp('OtherRevValType', Data) -> dec_OtherRevValType(Data); decode_disp('OtherRevVals', Data) -> dec_OtherRevVals(Data); decode_disp('CRLListID', Data) -> dec_CRLListID(Data); decode_disp('MessageImprint', Data) -> dec_MessageImprint(Data); decode_disp('TimeStampReq', Data) -> dec_TimeStampReq(Data); decode_disp('INSTANCE OF', Data) -> 'dec_INSTANCE OF'(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. %%================================ %% ContentInfo %%================================ enc_ContentInfo(Val) -> enc_ContentInfo(Val, [<<48>>]). enc_ContentInfo(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute contentType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_object_identifier(Cindex1, [<<6>>]), %%------------------------------------------------- %% attribute content(2) with type ASN1_OPEN_TYPE %%------------------------------------------------- {EncBytes2,EncLen2} = encode_open_type(Cindex2, [<<160>>]), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_ContentInfo(Tlv) -> dec_ContentInfo(Tlv, [16]). dec_ContentInfo(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute contentType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_object_identifier(V1, [6]), %%------------------------------------------------- %% attribute content(2) with type ASN1_OPEN_TYPE %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_open_type_as_binary(V2, [131072]), case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'ContentInfo',Term1,Term2}, Res1. %%================================ %% UnknownInfo %%================================ enc_UnknownInfo(Val) -> enc_UnknownInfo(Val, [<<5>>]). enc_UnknownInfo(Val, TagIn) -> encode_null(Val, TagIn). dec_UnknownInfo(Tlv) -> dec_UnknownInfo(Tlv, [5]). dec_UnknownInfo(Tlv, TagIn) -> decode_null(Tlv, TagIn). %%================================ %% CrlValidatedID %%================================ enc_CrlValidatedID(Val) -> enc_CrlValidatedID(Val, [<<48>>]). enc_CrlValidatedID(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute crlHash(1) External KEP:OtherHash %%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_OtherHash'(Cindex1, []), %%------------------------------------------------- %% attribute crlIdentifier(2) External KEP:CrlIdentifier OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_CrlIdentifier'(Cindex2, [<<48>>]) end, BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_CrlValidatedID(Tlv) -> dec_CrlValidatedID(Tlv, [16]). dec_CrlValidatedID(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute crlHash(1) External KEP:OtherHash %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'dec_OtherHash'(V1, []), %%------------------------------------------------- %% attribute crlIdentifier(2) External KEP:CrlIdentifier OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [{16,V2}|TempTlv3] -> {'dec_CrlIdentifier'(V2, []), TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'CrlValidatedID',Term1,Term2}, Res1. %%================================ %% OtherHash %%================================ enc_OtherHash(Val) -> enc_OtherHash(Val, []). enc_OtherHash(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of sha1Hash -> encode_restricted_string(element(2,Val), [<<4>>]); otherHash -> 'enc_OtherHashAlgAndValue'(element(2,Val), [<<48>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). dec_OtherHash(Tlv) -> dec_OtherHash(Tlv, []). dec_OtherHash(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'sha1Hash' {4, V1} -> {sha1Hash, decode_octet_string(V1, [])}; %% 'otherHash' {16, V1} -> {otherHash, 'dec_OtherHashAlgAndValue'(V1, [])}; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . %%================================ %% OcspListID %%================================ enc_OcspListID(Val) -> enc_OcspListID(Val, [<<48>>]). enc_OcspListID(Val, TagIn) -> {_,Cindex1} = Val, %%------------------------------------------------- %% attribute ocspResponses(1) with type SEQUENCE OF %%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_OcspListID_ocspResponses'(Cindex1, [<<48>>]), BytesSoFar = [EncBytes1], LenSoFar = EncLen1, encode_tags(TagIn, BytesSoFar, LenSoFar). %%================================ %% OcspListID_ocspResponses %%================================ enc_OcspListID_ocspResponses(Val, TagIn) -> {EncBytes,EncLen} = 'enc_OcspListID_ocspResponses_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_OcspListID_ocspResponses_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_OcspListID_ocspResponses_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_OcspResponsesID'(H, [<<48>>]), 'enc_OcspListID_ocspResponses_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_OcspListID(Tlv) -> dec_OcspListID(Tlv, [16]). dec_OcspListID(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute ocspResponses(1) with type SEQUENCE OF %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'dec_OcspListID_ocspResponses'(V1, [16]), case Tlv2 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv2}}}) % extra fields not allowed end, Res1 = {'OcspListID',Term1}, Res1. 'dec_OcspListID_ocspResponses'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_OcspResponsesID'(V1, [16]) || V1 <- Tlv1]. %%================================ %% OcspResponsesID %%================================ enc_OcspResponsesID(Val) -> enc_OcspResponsesID(Val, [<<48>>]). enc_OcspResponsesID(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute ocspIdentifier(1) External KEP:OcspIdentifier %%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_OcspIdentifier'(Cindex1, [<<48>>]), %%------------------------------------------------- %% attribute ocspRepHash(2) External KEP:OtherHash OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_OtherHash'(Cindex2, []) end, BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_OcspResponsesID(Tlv) -> dec_OcspResponsesID(Tlv, [16]). dec_OcspResponsesID(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute ocspIdentifier(1) External KEP:OcspIdentifier %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'dec_OcspIdentifier'(V1, [16]), %%------------------------------------------------- %% attribute ocspRepHash(2) External KEP:OtherHash OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [V2 = {4,_}|TempTlv3] -> {'dec_OtherHash'(V2, []), TempTlv3}; [V2 = {16,_}|TempTlv3] -> {'dec_OtherHash'(V2, []), TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'OcspResponsesID',Term1,Term2}, Res1. %%================================ %% OtherRevRefs %%================================ enc_OtherRevRefs(Val) -> enc_OtherRevRefs(Val, [<<48>>]). enc_OtherRevRefs(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute otherRevRefType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_object_identifier(Cindex1, [<<6>>]), %%------------------------------------------------- %% attribute otherRevRefs(2) with type ASN1_OPEN_TYPE %%------------------------------------------------- {EncBytes2,EncLen2} = encode_open_type(Cindex2, []), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_OtherRevRefs(Tlv) -> dec_OtherRevRefs(Tlv, [16]). dec_OtherRevRefs(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute otherRevRefType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_object_identifier(V1, [6]), %%------------------------------------------------- %% attribute otherRevRefs(2) with type ASN1_OPEN_TYPE %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_open_type_as_binary(V2, []), case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'OtherRevRefs',Term1,Term2}, Res1. %%================================ %% OcspIdentifier %%================================ enc_OcspIdentifier(Val) -> enc_OcspIdentifier(Val, [<<48>>]). enc_OcspIdentifier(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute ocspResponderID(1) External KEP:ResponderID %%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_ResponderID'(Cindex1, []), %%------------------------------------------------- %% attribute producedAt(2) with type GeneralizedTime %%------------------------------------------------- {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<24>>]), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_OcspIdentifier(Tlv) -> dec_OcspIdentifier(Tlv, [16]). dec_OcspIdentifier(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute ocspResponderID(1) External KEP:ResponderID %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'dec_ResponderID'(V1, []), %%------------------------------------------------- %% attribute producedAt(2) with type GeneralizedTime %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = begin binary_to_list(decode_restricted_string(V2, [24])) end , case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'OcspIdentifier',Term1,Term2}, Res1. %%================================ %% OtherRevRefType %%================================ enc_OtherRevRefType(Val) -> enc_OtherRevRefType(Val, [<<6>>]). enc_OtherRevRefType(Val, TagIn) -> encode_object_identifier(Val, TagIn). dec_OtherRevRefType(Tlv) -> dec_OtherRevRefType(Tlv, [6]). dec_OtherRevRefType(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% ContentType %%================================ enc_ContentType(Val) -> enc_ContentType(Val, [<<6>>]). enc_ContentType(Val, TagIn) -> encode_object_identifier(Val, TagIn). dec_ContentType(Tlv) -> dec_ContentType(Tlv, [6]). dec_ContentType(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% CMSVersion %%================================ enc_CMSVersion(Val) -> enc_CMSVersion(Val, [<<2>>]). enc_CMSVersion(Val, TagIn) -> encode_integer(Val, [{v0,0},{v1,1},{v2,2},{v3,3},{v4,4},{v5,5}], TagIn). dec_CMSVersion(Tlv) -> dec_CMSVersion(Tlv, [2]). dec_CMSVersion(Tlv, TagIn) -> begin Val1 = decode_integer(Tlv, TagIn), number2name(Val1, [{v0,0},{v1,1},{v2,2},{v3,3},{v4,4},{v5,5}]) end . %%================================ %% GeneralNames %%================================ enc_GeneralNames(Val) -> enc_GeneralNames(Val, [<<48>>]). enc_GeneralNames(Val, TagIn) -> {EncBytes,EncLen} = 'enc_GeneralNames_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_GeneralNames_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_GeneralNames_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_GeneralName'(H, []), 'enc_GeneralNames_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_GeneralNames(Tlv) -> dec_GeneralNames(Tlv, [16]). dec_GeneralNames(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_GeneralName'(V1, []) || V1 <- Tlv1]. %%================================ %% GeneralName %%================================ enc_GeneralName(Val) -> enc_GeneralName(Val, []). enc_GeneralName(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of otherName -> 'enc_INSTANCE OF'(element(2,Val), [<<160>>]); rfc822Name -> encode_restricted_string(element(2,Val), [<<129>>]); dNSName -> encode_restricted_string(element(2,Val), [<<130>>]); directoryName -> 'InformationFramework':'enc_Name'(element(2,Val), [<<164>>]); uniformResourceIdentifier -> encode_restricted_string(element(2,Val), [<<134>>]); iPAddress -> encode_restricted_string(element(2,Val), [<<135>>]); registeredID -> encode_object_identifier(element(2,Val), [<<136>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). dec_GeneralName(Tlv) -> dec_GeneralName(Tlv, []). dec_GeneralName(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'otherName' {131072, V1} -> {otherName, 'dec_INSTANCE OF'(V1, [])}; %% 'rfc822Name' {131073, V1} -> {rfc822Name, begin binary_to_list(decode_restricted_string(V1, [])) end }; %% 'dNSName' {131074, V1} -> {dNSName, begin binary_to_list(decode_restricted_string(V1, [])) end }; %% 'directoryName' {131076, V1} -> {directoryName, 'InformationFramework':'dec_Name'(V1, [])}; %% 'uniformResourceIdentifier' {131078, V1} -> {uniformResourceIdentifier, begin binary_to_list(decode_restricted_string(V1, [])) end }; %% 'iPAddress' {131079, V1} -> {iPAddress, decode_octet_string(V1, [])}; %% 'registeredID' {131080, V1} -> {registeredID, decode_object_identifier(V1, [])}; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . %%================================ %% TSAPolicyId %%================================ enc_TSAPolicyId(Val) -> enc_TSAPolicyId(Val, [<<6>>]). enc_TSAPolicyId(Val, TagIn) -> encode_object_identifier(Val, TagIn). dec_TSAPolicyId(Tlv) -> dec_TSAPolicyId(Tlv, [6]). dec_TSAPolicyId(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% SignatureAlgorithmIdentifier %%================================ enc_SignatureAlgorithmIdentifier(Val) -> enc_SignatureAlgorithmIdentifier(Val, [<<48>>]). enc_SignatureAlgorithmIdentifier(Val, TagIn) -> 'AuthenticationFramework':enc_AlgorithmIdentifier(Val, TagIn). dec_SignatureAlgorithmIdentifier(Tlv) -> dec_SignatureAlgorithmIdentifier(Tlv, [16]). dec_SignatureAlgorithmIdentifier(Tlv, TagIn) -> 'AuthenticationFramework':'dec_AlgorithmIdentifier'(Tlv, TagIn). %%================================ %% KeyIdentifier %%================================ enc_KeyIdentifier(Val) -> enc_KeyIdentifier(Val, [<<4>>]). enc_KeyIdentifier(Val, TagIn) -> encode_restricted_string(Val, TagIn). dec_KeyIdentifier(Tlv) -> dec_KeyIdentifier(Tlv, [4]). dec_KeyIdentifier(Tlv, TagIn) -> decode_octet_string(Tlv, TagIn). %%================================ %% SubjectKeyIdentifier %%================================ enc_SubjectKeyIdentifier(Val) -> enc_SubjectKeyIdentifier(Val, [<<4>>]). enc_SubjectKeyIdentifier(Val, TagIn) -> encode_restricted_string(Val, TagIn). dec_SubjectKeyIdentifier(Tlv) -> dec_SubjectKeyIdentifier(Tlv, [4]). dec_SubjectKeyIdentifier(Tlv, TagIn) -> decode_octet_string(Tlv, TagIn). %%================================ %% RevocationInfoChoices %%================================ enc_RevocationInfoChoices(Val) -> enc_RevocationInfoChoices(Val, [<<49>>]). enc_RevocationInfoChoices(Val, TagIn) -> {EncBytes,EncLen} = 'enc_RevocationInfoChoices_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_RevocationInfoChoices_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_RevocationInfoChoices_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'AuthenticationFramework':'enc_CertificateList'(H, [<<48>>]), 'enc_RevocationInfoChoices_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_RevocationInfoChoices(Tlv) -> dec_RevocationInfoChoices(Tlv, [17]). dec_RevocationInfoChoices(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['AuthenticationFramework':'dec_CertificateList'(V1, [16]) || V1 <- Tlv1]. %%================================ %% SignerInfos %%================================ enc_SignerInfos(Val) -> enc_SignerInfos(Val, [<<49>>]). enc_SignerInfos(Val, TagIn) -> {EncBytes,EncLen} = 'enc_SignerInfos_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_SignerInfos_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_SignerInfos_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_SignerInfo'(H, [<<48>>]), 'enc_SignerInfos_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_SignerInfos(Tlv) -> dec_SignerInfos(Tlv, [17]). dec_SignerInfos(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_SignerInfo'(V1, [16]) || V1 <- Tlv1]. %%================================ %% CertificateSet %%================================ enc_CertificateSet(Val) -> enc_CertificateSet(Val, [<<49>>]). enc_CertificateSet(Val, TagIn) -> {EncBytes,EncLen} = 'enc_CertificateSet_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_CertificateSet_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_CertificateSet_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'AuthenticationFramework':'enc_Certificate'(H, [<<48>>]), 'enc_CertificateSet_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_CertificateSet(Tlv) -> dec_CertificateSet(Tlv, [17]). dec_CertificateSet(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['AuthenticationFramework':'dec_Certificate'(V1, [16]) || V1 <- Tlv1]. %%================================ %% SignedData %%================================ enc_SignedData(Val) -> enc_SignedData(Val, [<<48>>]). enc_SignedData(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3,Cindex4,Cindex5,Cindex6} = Val, %%------------------------------------------------- %% attribute version(1) with type INTEGER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_integer(Cindex1, [{v0,0},{v1,1},{v2,2},{v3,3},{v4,4},{v5,5}], [<<2>>]), %%------------------------------------------------- %% attribute digestAlgorithms(2) External KEP:DigestAlgorithmIdentifiers %%------------------------------------------------- {EncBytes2,EncLen2} = 'enc_DigestAlgorithmIdentifiers'(Cindex2, [<<49>>]), %%------------------------------------------------- %% attribute encapContentInfo(3) External KEP:EncapsulatedContentInfo %%------------------------------------------------- {EncBytes3,EncLen3} = 'enc_EncapsulatedContentInfo'(Cindex3, [<<48>>]), %%------------------------------------------------- %% attribute certificates(4) External KEP:CertificateSet OPTIONAL %%------------------------------------------------- {EncBytes4,EncLen4} = case Cindex4 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_CertificateSet'(Cindex4, [<<160>>]) end, %%------------------------------------------------- %% attribute crls(5) External KEP:RevocationInfoChoices OPTIONAL %%------------------------------------------------- {EncBytes5,EncLen5} = case Cindex5 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_RevocationInfoChoices'(Cindex5, [<<161>>]) end, %%------------------------------------------------- %% attribute signerInfos(6) External KEP:SignerInfos %%------------------------------------------------- {EncBytes6,EncLen6} = 'enc_SignerInfos'(Cindex6, [<<49>>]), BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5, EncBytes6], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5 + EncLen6, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_SignedData(Tlv) -> dec_SignedData(Tlv, [16]). dec_SignedData(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute version(1) with type INTEGER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = begin Val1 = decode_integer(V1, [2]), number2name(Val1, [{v0,0},{v1,1},{v2,2},{v3,3},{v4,4},{v5,5}]) end , %%------------------------------------------------- %% attribute digestAlgorithms(2) External KEP:DigestAlgorithmIdentifiers %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = 'dec_DigestAlgorithmIdentifiers'(V2, [17]), %%------------------------------------------------- %% attribute encapContentInfo(3) External KEP:EncapsulatedContentInfo %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = 'dec_EncapsulatedContentInfo'(V3, [16]), %%------------------------------------------------- %% attribute certificates(4) External KEP:CertificateSet OPTIONAL %%------------------------------------------------- {Term4,Tlv5} = case Tlv4 of [{131072,V4}|TempTlv5] -> {'dec_CertificateSet'(V4, []), TempTlv5}; _ -> { asn1_NOVALUE, Tlv4} end, %%------------------------------------------------- %% attribute crls(5) External KEP:RevocationInfoChoices OPTIONAL %%------------------------------------------------- {Term5,Tlv6} = case Tlv5 of [{131073,V5}|TempTlv6] -> {'dec_RevocationInfoChoices'(V5, []), TempTlv6}; _ -> { asn1_NOVALUE, Tlv5} end, %%------------------------------------------------- %% attribute signerInfos(6) External KEP:SignerInfos %%------------------------------------------------- [V6|Tlv7] = Tlv6, Term6 = 'dec_SignerInfos'(V6, [17]), case Tlv7 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv7}}}) % extra fields not allowed end, Res1 = {'SignedData',Term1,Term2,Term3,Term4,Term5,Term6}, Res1. %%================================ %% EncapsulatedContentInfo %%================================ enc_EncapsulatedContentInfo(Val) -> enc_EncapsulatedContentInfo(Val, [<<48>>]). enc_EncapsulatedContentInfo(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute eContentType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_object_identifier(Cindex1, [<<6>>]), %%------------------------------------------------- %% attribute eContent(2) with type OCTET STRING OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_restricted_string(Cindex2, [<<4>>,<<160>>]) end, BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_EncapsulatedContentInfo(Tlv) -> dec_EncapsulatedContentInfo(Tlv, [16]). dec_EncapsulatedContentInfo(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute eContentType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_object_identifier(V1, [6]), %%------------------------------------------------- %% attribute eContent(2) with type OCTET STRING OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [{131072,V2}|TempTlv3] -> {decode_octet_string(V2, [4]), TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'EncapsulatedContentInfo',Term1,Term2}, Res1. %%================================ %% SignerInfo %%================================ enc_SignerInfo(Val) -> enc_SignerInfo(Val, [<<48>>]). enc_SignerInfo(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3,Cindex4,Cindex5,Cindex6,Cindex7} = Val, %%------------------------------------------------- %% attribute version(1) with type INTEGER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_integer(Cindex1, [{v0,0},{v1,1},{v2,2},{v3,3},{v4,4},{v5,5}], [<<2>>]), %%------------------------------------------------- %% attribute sid(2) External KEP:SignerIdentifier %%------------------------------------------------- {EncBytes2,EncLen2} = 'enc_SignerIdentifier'(Cindex2, []), %%------------------------------------------------- %% attribute digestAlgorithm(3) External KEP:DigestAlgorithmIdentifier %%------------------------------------------------- {EncBytes3,EncLen3} = 'enc_DigestAlgorithmIdentifier'(Cindex3, [<<48>>]), %%------------------------------------------------- %% attribute signedAttrs(4) External KEP:SignedAttributes OPTIONAL %%------------------------------------------------- {EncBytes4,EncLen4} = case Cindex4 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_SignedAttributes'(Cindex4, [<<160>>]) end, %%------------------------------------------------- %% attribute signatureAlgorithm(5) External KEP:SignatureAlgorithmIdentifier %%------------------------------------------------- {EncBytes5,EncLen5} = 'enc_SignatureAlgorithmIdentifier'(Cindex5, [<<48>>]), %%------------------------------------------------- %% attribute signature(6) with type OCTET STRING %%------------------------------------------------- {EncBytes6,EncLen6} = encode_restricted_string(Cindex6, [<<4>>]), %%------------------------------------------------- %% attribute unsignedAttrs(7) External KEP:UnsignedAttributes OPTIONAL %%------------------------------------------------- {EncBytes7,EncLen7} = case Cindex7 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_UnsignedAttributes'(Cindex7, [<<161>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5, EncBytes6, EncBytes7], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5 + EncLen6 + EncLen7, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_SignerInfo(Tlv) -> dec_SignerInfo(Tlv, [16]). dec_SignerInfo(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute version(1) with type INTEGER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = begin Val1 = decode_integer(V1, [2]), number2name(Val1, [{v0,0},{v1,1},{v2,2},{v3,3},{v4,4},{v5,5}]) end , %%------------------------------------------------- %% attribute sid(2) External KEP:SignerIdentifier %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = 'dec_SignerIdentifier'(V2, []), %%------------------------------------------------- %% attribute digestAlgorithm(3) External KEP:DigestAlgorithmIdentifier %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = 'dec_DigestAlgorithmIdentifier'(V3, [16]), %%------------------------------------------------- %% attribute signedAttrs(4) External KEP:SignedAttributes OPTIONAL %%------------------------------------------------- {Term4,Tlv5} = case Tlv4 of [{131072,V4}|TempTlv5] -> {'dec_SignedAttributes'(V4, []), TempTlv5}; _ -> { asn1_NOVALUE, Tlv4} end, %%------------------------------------------------- %% attribute signatureAlgorithm(5) External KEP:SignatureAlgorithmIdentifier %%------------------------------------------------- [V5|Tlv6] = Tlv5, Term5 = 'dec_SignatureAlgorithmIdentifier'(V5, [16]), %%------------------------------------------------- %% attribute signature(6) with type OCTET STRING %%------------------------------------------------- [V6|Tlv7] = Tlv6, Term6 = decode_octet_string(V6, [4]), %%------------------------------------------------- %% attribute unsignedAttrs(7) External KEP:UnsignedAttributes OPTIONAL %%------------------------------------------------- {Term7,Tlv8} = case Tlv7 of [{131073,V7}|TempTlv8] -> {'dec_UnsignedAttributes'(V7, []), TempTlv8}; _ -> { asn1_NOVALUE, Tlv7} end, case Tlv8 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv8}}}) % extra fields not allowed end, Res1 = {'SignerInfo',Term1,Term2,Term3,Term4,Term5,Term6,Term7}, Res1. %%================================ %% SignerIdentifier %%================================ enc_SignerIdentifier(Val) -> enc_SignerIdentifier(Val, []). enc_SignerIdentifier(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of issuerAndSerialNumber -> 'enc_IssuerAndSerialNumber'(element(2,Val), [<<48>>]); subjectKeyIdentifier -> encode_restricted_string(element(2,Val), [<<128>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). dec_SignerIdentifier(Tlv) -> dec_SignerIdentifier(Tlv, []). dec_SignerIdentifier(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'issuerAndSerialNumber' {16, V1} -> {issuerAndSerialNumber, 'dec_IssuerAndSerialNumber'(V1, [])}; %% 'subjectKeyIdentifier' {131072, V1} -> {subjectKeyIdentifier, decode_octet_string(V1, [])}; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . %%================================ %% IssuerAndSerialNumber %%================================ enc_IssuerAndSerialNumber(Val) -> enc_IssuerAndSerialNumber(Val, [<<48>>]). enc_IssuerAndSerialNumber(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute issuer(1) External InformationFramework:Name %%------------------------------------------------- {EncBytes1,EncLen1} = 'InformationFramework':'enc_Name'(Cindex1, []), %%------------------------------------------------- %% attribute serialNumber(2) with type INTEGER %%------------------------------------------------- {EncBytes2,EncLen2} = encode_integer(Cindex2, [<<2>>]), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_IssuerAndSerialNumber(Tlv) -> dec_IssuerAndSerialNumber(Tlv, [16]). dec_IssuerAndSerialNumber(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute issuer(1) External InformationFramework:Name %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'InformationFramework':'dec_Name'(V1, []), %%------------------------------------------------- %% attribute serialNumber(2) with type INTEGER %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_integer(V2, [2]), case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'IssuerAndSerialNumber',Term1,Term2}, Res1. %%================================ %% Hash %%================================ enc_Hash(Val) -> enc_Hash(Val, [<<4>>]). enc_Hash(Val, TagIn) -> encode_restricted_string(Val, TagIn). dec_Hash(Tlv) -> dec_Hash(Tlv, [4]). dec_Hash(Tlv, TagIn) -> decode_octet_string(Tlv, TagIn). %%================================ %% IssuerSerial %%================================ enc_IssuerSerial(Val) -> enc_IssuerSerial(Val, [<<48>>]). enc_IssuerSerial(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute issuer(1) External KEP:GeneralNames %%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_GeneralNames'(Cindex1, [<<48>>]), %%------------------------------------------------- %% attribute serialNumber(2) with type INTEGER %%------------------------------------------------- {EncBytes2,EncLen2} = encode_integer(Cindex2, [<<2>>]), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_IssuerSerial(Tlv) -> dec_IssuerSerial(Tlv, [16]). dec_IssuerSerial(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute issuer(1) External KEP:GeneralNames %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'dec_GeneralNames'(V1, [16]), %%------------------------------------------------- %% attribute serialNumber(2) with type INTEGER %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_integer(V2, [2]), case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'IssuerSerial',Term1,Term2}, Res1. %%================================ %% ESSCertIDv2 %%================================ enc_ESSCertIDv2(Val) -> enc_ESSCertIDv2(Val, [<<48>>]). enc_ESSCertIDv2(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3} = Val, %%------------------------------------------------- %% attribute hashAlgorithm(1) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- {EncBytes1,EncLen1} = 'AuthenticationFramework':'enc_AlgorithmIdentifier'(Cindex1, [<<48>>]), %%------------------------------------------------- %% attribute certHash(2) with type OCTET STRING %%------------------------------------------------- {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]), %%------------------------------------------------- %% attribute issuerSerial(3) External KEP:IssuerSerial %%------------------------------------------------- {EncBytes3,EncLen3} = 'enc_IssuerSerial'(Cindex3, [<<48>>]), BytesSoFar = [EncBytes1, EncBytes2, EncBytes3], LenSoFar = EncLen1 + EncLen2 + EncLen3, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_ESSCertIDv2(Tlv) -> dec_ESSCertIDv2(Tlv, [16]). dec_ESSCertIDv2(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute hashAlgorithm(1) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'AuthenticationFramework':'dec_AlgorithmIdentifier'(V1, [16]), %%------------------------------------------------- %% attribute certHash(2) with type OCTET STRING %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_octet_string(V2, [4]), %%------------------------------------------------- %% attribute issuerSerial(3) External KEP:IssuerSerial %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = 'dec_IssuerSerial'(V3, [16]), case Tlv4 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed end, Res1 = {'ESSCertIDv2',Term1,Term2,Term3}, Res1. %%================================ %% OtherHashValue %%================================ enc_OtherHashValue(Val) -> enc_OtherHashValue(Val, [<<4>>]). enc_OtherHashValue(Val, TagIn) -> encode_restricted_string(Val, TagIn). dec_OtherHashValue(Tlv) -> dec_OtherHashValue(Tlv, [4]). dec_OtherHashValue(Tlv, TagIn) -> decode_octet_string(Tlv, TagIn). %%================================ %% OtherHashAlgAndValue %%================================ enc_OtherHashAlgAndValue(Val) -> enc_OtherHashAlgAndValue(Val, [<<48>>]). enc_OtherHashAlgAndValue(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute hashAlgorithm(1) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- {EncBytes1,EncLen1} = 'AuthenticationFramework':'enc_AlgorithmIdentifier'(Cindex1, [<<48>>]), %%------------------------------------------------- %% attribute hashValue(2) with type OCTET STRING %%------------------------------------------------- {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_OtherHashAlgAndValue(Tlv) -> dec_OtherHashAlgAndValue(Tlv, [16]). dec_OtherHashAlgAndValue(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute hashAlgorithm(1) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'AuthenticationFramework':'dec_AlgorithmIdentifier'(V1, [16]), %%------------------------------------------------- %% attribute hashValue(2) with type OCTET STRING %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_octet_string(V2, [4]), case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'OtherHashAlgAndValue',Term1,Term2}, Res1. %%================================ %% SPuri %%================================ enc_SPuri(Val) -> enc_SPuri(Val, [<<22>>]). enc_SPuri(Val, TagIn) -> encode_restricted_string(Val, TagIn). dec_SPuri(Tlv) -> dec_SPuri(Tlv, [22]). dec_SPuri(Tlv, TagIn) -> begin binary_to_list(decode_restricted_string(Tlv, TagIn)) end . %%================================ %% SigPolicyId %%================================ enc_SigPolicyId(Val) -> enc_SigPolicyId(Val, [<<6>>]). enc_SigPolicyId(Val, TagIn) -> encode_object_identifier(Val, TagIn). dec_SigPolicyId(Tlv) -> dec_SigPolicyId(Tlv, [6]). dec_SigPolicyId(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% SigPolicyHash %%================================ enc_SigPolicyHash(Val) -> enc_SigPolicyHash(Val, [<<48>>]). enc_SigPolicyHash(Val, TagIn) -> enc_OtherHashAlgAndValue(Val, TagIn). dec_SigPolicyHash(Tlv) -> dec_SigPolicyHash(Tlv, [16]). dec_SigPolicyHash(Tlv, TagIn) -> 'dec_OtherHashAlgAndValue'(Tlv, TagIn). %%================================ %% SigPolicyQualifierId %%================================ enc_SigPolicyQualifierId(Val) -> enc_SigPolicyQualifierId(Val, [<<6>>]). enc_SigPolicyQualifierId(Val, TagIn) -> encode_object_identifier(Val, TagIn). dec_SigPolicyQualifierId(Tlv) -> dec_SigPolicyQualifierId(Tlv, [6]). dec_SigPolicyQualifierId(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% SignaturePolicyIdentifier %%================================ enc_SignaturePolicyIdentifier(Val) -> enc_SignaturePolicyIdentifier(Val, []). enc_SignaturePolicyIdentifier(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of signaturePolicy -> 'enc_SignaturePolicyId'(element(2,Val), [<<48>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). dec_SignaturePolicyIdentifier(Tlv) -> dec_SignaturePolicyIdentifier(Tlv, []). dec_SignaturePolicyIdentifier(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'signaturePolicy' {16, V1} -> {signaturePolicy, 'dec_SignaturePolicyId'(V1, [])}; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . %%================================ %% SigPolicyQualifierInfo %%================================ enc_SigPolicyQualifierInfo(Val) -> enc_SigPolicyQualifierInfo(Val, [<<48>>]). enc_SigPolicyQualifierInfo(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute sigPolicyQualifierId(1) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_object_identifier(Cindex1, [<<6>>]), %%------------------------------------------------- %% attribute sigQualifier(2) with type ASN1_OPEN_TYPE %%------------------------------------------------- {EncBytes2,EncLen2} = encode_open_type(Cindex2, []), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_SigPolicyQualifierInfo(Tlv) -> dec_SigPolicyQualifierInfo(Tlv, [16]). dec_SigPolicyQualifierInfo(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute sigPolicyQualifierId(1) with type OBJECT IDENTIFIER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_object_identifier(V1, [6]), %%------------------------------------------------- %% attribute sigQualifier(2) with type ASN1_OPEN_TYPE %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_open_type_as_binary(V2, []), case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'SigPolicyQualifierInfo',Term1,Term2}, Res1. %%================================ %% SignaturePolicyId %%================================ enc_SignaturePolicyId(Val) -> enc_SignaturePolicyId(Val, [<<48>>]). enc_SignaturePolicyId(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute sigPolicyId(1) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_object_identifier(Cindex1, [<<6>>]), %%------------------------------------------------- %% attribute sigPolicyHash(2) External KEP:SigPolicyHash OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_SigPolicyHash'(Cindex2, [<<48>>]) end, BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_SignaturePolicyId(Tlv) -> dec_SignaturePolicyId(Tlv, [16]). dec_SignaturePolicyId(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute sigPolicyId(1) with type OBJECT IDENTIFIER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_object_identifier(V1, [6]), %%------------------------------------------------- %% attribute sigPolicyHash(2) External KEP:SigPolicyHash OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [{16,V2}|TempTlv3] -> {'dec_SigPolicyHash'(V2, []), TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'SignaturePolicyId',Term1,Term2}, Res1. %%================================ %% DigestAlgorithmIdentifiers %%================================ enc_DigestAlgorithmIdentifiers(Val) -> enc_DigestAlgorithmIdentifiers(Val, [<<49>>]). enc_DigestAlgorithmIdentifiers(Val, TagIn) -> {EncBytes,EncLen} = 'enc_DigestAlgorithmIdentifiers_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_DigestAlgorithmIdentifiers_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_DigestAlgorithmIdentifiers_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_DigestAlgorithmIdentifier'(H, [<<48>>]), 'enc_DigestAlgorithmIdentifiers_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_DigestAlgorithmIdentifiers(Tlv) -> dec_DigestAlgorithmIdentifiers(Tlv, [17]). dec_DigestAlgorithmIdentifiers(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_DigestAlgorithmIdentifier'(V1, [16]) || V1 <- Tlv1]. %%================================ %% DigestAlgorithmIdentifier %%================================ enc_DigestAlgorithmIdentifier(Val) -> enc_DigestAlgorithmIdentifier(Val, [<<48>>]). enc_DigestAlgorithmIdentifier(Val, TagIn) -> 'AuthenticationFramework':enc_AlgorithmIdentifier(Val, TagIn). dec_DigestAlgorithmIdentifier(Tlv) -> dec_DigestAlgorithmIdentifier(Tlv, [16]). dec_DigestAlgorithmIdentifier(Tlv, TagIn) -> 'AuthenticationFramework':'dec_AlgorithmIdentifier'(Tlv, TagIn). %%================================ %% CertificateSerialNumber %%================================ enc_CertificateSerialNumber(Val) -> enc_CertificateSerialNumber(Val, [<<2>>]). enc_CertificateSerialNumber(Val, TagIn) -> encode_integer(Val, TagIn). dec_CertificateSerialNumber(Tlv) -> dec_CertificateSerialNumber(Tlv, [2]). dec_CertificateSerialNumber(Tlv, TagIn) -> decode_integer(Tlv, TagIn). %%================================ %% SignedAttributes %%================================ enc_SignedAttributes(Val) -> enc_SignedAttributes(Val, [<<49>>]). enc_SignedAttributes(Val, TagIn) -> {EncBytes,EncLen} = 'enc_SignedAttributes_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_SignedAttributes_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_SignedAttributes_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'InformationFramework':'enc_Attribute'(H, [<<48>>]), 'enc_SignedAttributes_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_SignedAttributes(Tlv) -> dec_SignedAttributes(Tlv, [17]). dec_SignedAttributes(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['InformationFramework':'dec_Attribute'(V1, [16]) || V1 <- Tlv1]. %%================================ %% UnsignedAttributes %%================================ enc_UnsignedAttributes(Val) -> enc_UnsignedAttributes(Val, [<<49>>]). enc_UnsignedAttributes(Val, TagIn) -> {EncBytes,EncLen} = 'enc_UnsignedAttributes_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_UnsignedAttributes_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_UnsignedAttributes_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'InformationFramework':'enc_Attribute'(H, [<<48>>]), 'enc_UnsignedAttributes_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_UnsignedAttributes(Tlv) -> dec_UnsignedAttributes(Tlv, [17]). dec_UnsignedAttributes(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['InformationFramework':'dec_Attribute'(V1, [16]) || V1 <- Tlv1]. %%================================ %% Attribute %%================================ enc_Attribute(Val) -> enc_Attribute(Val, [<<48>>]). enc_Attribute(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute attrType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_object_identifier(Cindex1, [<<6>>]), %%------------------------------------------------- %% attribute attrValues(2) with type SET OF %%------------------------------------------------- {EncBytes2,EncLen2} = 'enc_Attribute_attrValues'(Cindex2, [<<49>>]), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). %%================================ %% Attribute_attrValues %%================================ enc_Attribute_attrValues(Val, TagIn) -> {EncBytes,EncLen} = 'enc_Attribute_attrValues_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_Attribute_attrValues_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_Attribute_attrValues_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_AttributeValue'(H, []), 'enc_Attribute_attrValues_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_Attribute(Tlv) -> dec_Attribute(Tlv, [16]). dec_Attribute(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute attrType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_object_identifier(V1, [6]), %%------------------------------------------------- %% attribute attrValues(2) with type SET OF %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = 'dec_Attribute_attrValues'(V2, [17]), case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'Attribute',Term1,Term2}, Res1. 'dec_Attribute_attrValues'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_AttributeValue'(V1, []) || V1 <- Tlv1]. %%================================ %% AttributeValue %%================================ enc_AttributeValue(Val) -> enc_AttributeValue(Val, []). enc_AttributeValue(Val, TagIn) -> %% OPEN TYPE encode_open_type(Val, TagIn). dec_AttributeValue(Tlv) -> dec_AttributeValue(Tlv, []). dec_AttributeValue(Tlv, TagIn) -> decode_open_type_as_binary(Tlv, TagIn). %%================================ %% MessageDigest %%================================ enc_MessageDigest(Val) -> enc_MessageDigest(Val, [<<4>>]). enc_MessageDigest(Val, TagIn) -> encode_restricted_string(Val, TagIn). dec_MessageDigest(Tlv) -> dec_MessageDigest(Tlv, [4]). dec_MessageDigest(Tlv, TagIn) -> decode_octet_string(Tlv, TagIn). %%================================ %% SigningCertificateV2 %%================================ enc_SigningCertificateV2(Val) -> enc_SigningCertificateV2(Val, [<<48>>]). enc_SigningCertificateV2(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute certs(1) with type SEQUENCE OF %%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_SigningCertificateV2_certs'(Cindex1, [<<48>>]), %%------------------------------------------------- %% attribute policies(2) with type SEQUENCE OF OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_SigningCertificateV2_policies'(Cindex2, [<<48>>]) end, BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). %%================================ %% SigningCertificateV2_certs %%================================ enc_SigningCertificateV2_certs(Val, TagIn) -> {EncBytes,EncLen} = 'enc_SigningCertificateV2_certs_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_SigningCertificateV2_certs_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_SigningCertificateV2_certs_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_ESSCertIDv2'(H, [<<48>>]), 'enc_SigningCertificateV2_certs_components'(T,[EncBytes|AccBytes], AccLen + EncLen). %%================================ %% SigningCertificateV2_policies %%================================ enc_SigningCertificateV2_policies(Val, TagIn) -> {EncBytes,EncLen} = 'enc_SigningCertificateV2_policies_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_SigningCertificateV2_policies_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_SigningCertificateV2_policies_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'CertificateExtensions':'enc_PolicyInformation'(H, [<<48>>]), 'enc_SigningCertificateV2_policies_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_SigningCertificateV2(Tlv) -> dec_SigningCertificateV2(Tlv, [16]). dec_SigningCertificateV2(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute certs(1) with type SEQUENCE OF %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'dec_SigningCertificateV2_certs'(V1, [16]), %%------------------------------------------------- %% attribute policies(2) with type SEQUENCE OF OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [{16,V2}|TempTlv3] -> {'dec_SigningCertificateV2_policies'(V2, []), TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'SigningCertificateV2',Term1,Term2}, Res1. 'dec_SigningCertificateV2_certs'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_ESSCertIDv2'(V1, [16]) || V1 <- Tlv1]. 'dec_SigningCertificateV2_policies'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['CertificateExtensions':'dec_PolicyInformation'(V1, [16]) || V1 <- Tlv1]. %%================================ %% SignaturePolicyImplied %%================================ enc_SignaturePolicyImplied(Val) -> enc_SignaturePolicyImplied(Val, [<<5>>]). enc_SignaturePolicyImplied(Val, TagIn) -> encode_null(Val, TagIn). dec_SignaturePolicyImplied(Tlv) -> dec_SignaturePolicyImplied(Tlv, [5]). dec_SignaturePolicyImplied(Tlv, TagIn) -> decode_null(Tlv, TagIn). %%================================ %% DisplayText %%================================ enc_DisplayText(Val) -> enc_DisplayText(Val, []). enc_DisplayText(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of visibleString -> encode_restricted_string(element(2,Val), [<<26>>]); bmpString -> encode_BMP_string(element(2,Val), [<<30>>]); utf8String -> encode_UTF8_string(element(2,Val), [<<12>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). dec_DisplayText(Tlv) -> dec_DisplayText(Tlv, []). dec_DisplayText(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'visibleString' {26, V1} -> {visibleString, begin Val1 = decode_restricted_string(V1, []), C1 = byte_size(Val1), if 1 =< C1, C1 =< 200 -> binary_to_list(Val1); true -> exit({error,{asn1,bad_range}}) end end}; %% 'bmpString' {30, V1} -> {bmpString, begin Val2 = decode_BMP_string(V1, []), C2 = length(Val2), if 1 =< C2, C2 =< 200 -> Val2; true -> exit({error,{asn1,bad_range}}) end end}; %% 'utf8String' {12, V1} -> {utf8String, decode_UTF8_string(V1, [])}; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . %%================================ %% CrlOcspRef %%================================ enc_CrlOcspRef(Val) -> enc_CrlOcspRef(Val, [<<48>>]). enc_CrlOcspRef(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3} = Val, %%------------------------------------------------- %% attribute crlids(1) External KEP:CRLListID OPTIONAL %%------------------------------------------------- {EncBytes1,EncLen1} = case Cindex1 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_CRLListID'(Cindex1, [<<160>>]) end, %%------------------------------------------------- %% attribute ocspids(2) External KEP:OcspListID OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_OcspListID'(Cindex2, [<<161>>]) end, %%------------------------------------------------- %% attribute otherRev(3) External KEP:OtherRevRefs OPTIONAL %%------------------------------------------------- {EncBytes3,EncLen3} = case Cindex3 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_OtherRevRefs'(Cindex3, [<<162>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3], LenSoFar = EncLen1 + EncLen2 + EncLen3, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_CrlOcspRef(Tlv) -> dec_CrlOcspRef(Tlv, [16]). dec_CrlOcspRef(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute crlids(1) External KEP:CRLListID OPTIONAL %%------------------------------------------------- {Term1,Tlv2} = case Tlv1 of [{131072,V1}|TempTlv2] -> {'dec_CRLListID'(V1, []), TempTlv2}; _ -> { asn1_NOVALUE, Tlv1} end, %%------------------------------------------------- %% attribute ocspids(2) External KEP:OcspListID OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [{131073,V2}|TempTlv3] -> {'dec_OcspListID'(V2, []), TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, %%------------------------------------------------- %% attribute otherRev(3) External KEP:OtherRevRefs OPTIONAL %%------------------------------------------------- {Term3,Tlv4} = case Tlv3 of [{131074,V3}|TempTlv4] -> {'dec_OtherRevRefs'(V3, []), TempTlv4}; _ -> { asn1_NOVALUE, Tlv3} end, case Tlv4 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed end, Res1 = {'CrlOcspRef',Term1,Term2,Term3}, Res1. %%================================ %% CrlIdentifier %%================================ enc_CrlIdentifier(Val) -> enc_CrlIdentifier(Val, [<<48>>]). enc_CrlIdentifier(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3} = Val, %%------------------------------------------------- %% attribute crlissuer(1) External InformationFramework:Name %%------------------------------------------------- {EncBytes1,EncLen1} = 'InformationFramework':'enc_Name'(Cindex1, []), %%------------------------------------------------- %% attribute crlIssuedTime(2) with type UTCTime %%------------------------------------------------- {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<23>>]), %%------------------------------------------------- %% attribute crlNumber(3) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes3,EncLen3} = case Cindex3 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex3, [<<2>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3], LenSoFar = EncLen1 + EncLen2 + EncLen3, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_CrlIdentifier(Tlv) -> dec_CrlIdentifier(Tlv, [16]). dec_CrlIdentifier(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute crlissuer(1) External InformationFramework:Name %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'InformationFramework':'dec_Name'(V1, []), %%------------------------------------------------- %% attribute crlIssuedTime(2) with type UTCTime %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = begin binary_to_list(decode_restricted_string(V2, [23])) end , %%------------------------------------------------- %% attribute crlNumber(3) with type INTEGER OPTIONAL %%------------------------------------------------- {Term3,Tlv4} = case Tlv3 of [{2,V3}|TempTlv4] -> {decode_integer(V3, []), TempTlv4}; _ -> { asn1_NOVALUE, Tlv3} end, case Tlv4 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed end, Res1 = {'CrlIdentifier',Term1,Term2,Term3}, Res1. %%================================ %% BasicOCSPResponse %%================================ enc_BasicOCSPResponse(Val) -> enc_BasicOCSPResponse(Val, [<<48>>]). enc_BasicOCSPResponse(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3,Cindex4} = Val, %%------------------------------------------------- %% attribute tbsResponseData(1) External KEP:ResponseData %%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_ResponseData'(Cindex1, [<<48>>]), %%------------------------------------------------- %% attribute signatureAlgorithm(2) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- {EncBytes2,EncLen2} = 'AuthenticationFramework':'enc_AlgorithmIdentifier'(Cindex2, [<<48>>]), %%------------------------------------------------- %% attribute signature(3) with type BIT STRING %%------------------------------------------------- {EncBytes3,EncLen3} = encode_unnamed_bit_string(Cindex3, [<<3>>]), %%------------------------------------------------- %% attribute certs(4) with type SEQUENCE OF OPTIONAL %%------------------------------------------------- {EncBytes4,EncLen4} = case Cindex4 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_BasicOCSPResponse_certs'(Cindex4, [<<48>>,<<160>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4, encode_tags(TagIn, BytesSoFar, LenSoFar). %%================================ %% BasicOCSPResponse_certs %%================================ enc_BasicOCSPResponse_certs(Val, TagIn) -> {EncBytes,EncLen} = 'enc_BasicOCSPResponse_certs_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_BasicOCSPResponse_certs_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_BasicOCSPResponse_certs_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'AuthenticationFramework':'enc_Certificate'(H, [<<48>>]), 'enc_BasicOCSPResponse_certs_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_BasicOCSPResponse(Tlv) -> dec_BasicOCSPResponse(Tlv, [16]). dec_BasicOCSPResponse(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute tbsResponseData(1) External KEP:ResponseData %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'dec_ResponseData'(V1, [16]), %%------------------------------------------------- %% attribute signatureAlgorithm(2) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = 'AuthenticationFramework':'dec_AlgorithmIdentifier'(V2, [16]), %%------------------------------------------------- %% attribute signature(3) with type BIT STRING %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = decode_native_bit_string(V3, [3]), %%------------------------------------------------- %% attribute certs(4) with type SEQUENCE OF OPTIONAL %%------------------------------------------------- {Term4,Tlv5} = case Tlv4 of [{131072,V4}|TempTlv5] -> {'dec_BasicOCSPResponse_certs'(V4, [16]), TempTlv5}; _ -> { asn1_NOVALUE, Tlv4} end, case Tlv5 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv5}}}) % extra fields not allowed end, Res1 = {'BasicOCSPResponse',Term1,Term2,Term3,Term4}, Res1. 'dec_BasicOCSPResponse_certs'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['AuthenticationFramework':'dec_Certificate'(V1, [16]) || V1 <- Tlv1]. %%================================ %% ResponseData %%================================ enc_ResponseData(Val) -> enc_ResponseData(Val, [<<48>>]). enc_ResponseData(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3,Cindex4,Cindex5} = Val, %%------------------------------------------------- %% attribute version(1) with type INTEGER DEFAULT = 0 %%------------------------------------------------- {EncBytes1,EncLen1} = case Cindex1 of asn1_DEFAULT -> {<<>>,0}; _ when Cindex1 =:= 0 -> {<<>>,0}; _ -> encode_integer(Cindex1, [{v1,0},{v2,1},{v3,2}], [<<2>>,<<160>>]) end, %%------------------------------------------------- %% attribute responderID(2) External KEP:ResponderID %%------------------------------------------------- {EncBytes2,EncLen2} = 'enc_ResponderID'(Cindex2, []), %%------------------------------------------------- %% attribute producedAt(3) with type GeneralizedTime %%------------------------------------------------- {EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<24>>]), %%------------------------------------------------- %% attribute responses(4) with type SEQUENCE OF %%------------------------------------------------- {EncBytes4,EncLen4} = 'enc_ResponseData_responses'(Cindex4, [<<48>>]), %%------------------------------------------------- %% attribute responseExtensions(5) External AuthenticationFramework:Extensions OPTIONAL %%------------------------------------------------- {EncBytes5,EncLen5} = case Cindex5 of asn1_NOVALUE -> {<<>>,0}; _ -> 'AuthenticationFramework':'enc_Extensions'(Cindex5, [<<48>>,<<161>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5, encode_tags(TagIn, BytesSoFar, LenSoFar). %%================================ %% ResponseData_responses %%================================ enc_ResponseData_responses(Val, TagIn) -> {EncBytes,EncLen} = 'enc_ResponseData_responses_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_ResponseData_responses_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_ResponseData_responses_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_SingleResponse'(H, [<<48>>]), 'enc_ResponseData_responses_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_ResponseData(Tlv) -> dec_ResponseData(Tlv, [16]). dec_ResponseData(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute version(1) with type INTEGER DEFAULT = 0 %%------------------------------------------------- {Term1,Tlv2} = case Tlv1 of [{131072,V1}|TempTlv2] -> {begin Val1 = decode_integer(V1, [2]), number2name(Val1, [{v1,0},{v2,1},{v3,2}]) end , TempTlv2}; _ -> {0,Tlv1} end, %%------------------------------------------------- %% attribute responderID(2) External KEP:ResponderID %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = 'dec_ResponderID'(V2, []), %%------------------------------------------------- %% attribute producedAt(3) with type GeneralizedTime %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = begin binary_to_list(decode_restricted_string(V3, [24])) end , %%------------------------------------------------- %% attribute responses(4) with type SEQUENCE OF %%------------------------------------------------- [V4|Tlv5] = Tlv4, Term4 = 'dec_ResponseData_responses'(V4, [16]), %%------------------------------------------------- %% attribute responseExtensions(5) External AuthenticationFramework:Extensions OPTIONAL %%------------------------------------------------- {Term5,Tlv6} = case Tlv5 of [{131073,V5}|TempTlv6] -> {'AuthenticationFramework':'dec_Extensions'(V5, [16]), TempTlv6}; _ -> { asn1_NOVALUE, Tlv5} end, case Tlv6 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv6}}}) % extra fields not allowed end, Res1 = {'ResponseData',Term1,Term2,Term3,Term4,Term5}, Res1. 'dec_ResponseData_responses'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_SingleResponse'(V1, [16]) || V1 <- Tlv1]. %%================================ %% ResponderID %%================================ enc_ResponderID(Val) -> enc_ResponderID(Val, []). enc_ResponderID(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of byName -> 'InformationFramework':'enc_Name'(element(2,Val), [<<161>>]); byKey -> encode_restricted_string(element(2,Val), [<<130>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). dec_ResponderID(Tlv) -> dec_ResponderID(Tlv, []). dec_ResponderID(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'byName' {131073, V1} -> {byName, 'InformationFramework':'dec_Name'(V1, [])}; %% 'byKey' {131074, V1} -> {byKey, decode_octet_string(V1, [])}; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . %%================================ %% KeyHash %%================================ enc_KeyHash(Val) -> enc_KeyHash(Val, [<<4>>]). enc_KeyHash(Val, TagIn) -> encode_restricted_string(Val, TagIn). dec_KeyHash(Tlv) -> dec_KeyHash(Tlv, [4]). dec_KeyHash(Tlv, TagIn) -> decode_octet_string(Tlv, TagIn). %%================================ %% CertID %%================================ enc_CertID(Val) -> enc_CertID(Val, [<<48>>]). enc_CertID(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3,Cindex4} = Val, %%------------------------------------------------- %% attribute hashAlgorithm(1) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- {EncBytes1,EncLen1} = 'AuthenticationFramework':'enc_AlgorithmIdentifier'(Cindex1, [<<48>>]), %%------------------------------------------------- %% attribute issuerNameHash(2) with type OCTET STRING %%------------------------------------------------- {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]), %%------------------------------------------------- %% attribute issuerKeyHash(3) with type OCTET STRING %%------------------------------------------------- {EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<4>>]), %%------------------------------------------------- %% attribute serialNumber(4) with type INTEGER %%------------------------------------------------- {EncBytes4,EncLen4} = encode_integer(Cindex4, [<<2>>]), BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_CertID(Tlv) -> dec_CertID(Tlv, [16]). dec_CertID(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute hashAlgorithm(1) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'AuthenticationFramework':'dec_AlgorithmIdentifier'(V1, [16]), %%------------------------------------------------- %% attribute issuerNameHash(2) with type OCTET STRING %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_octet_string(V2, [4]), %%------------------------------------------------- %% attribute issuerKeyHash(3) with type OCTET STRING %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = decode_octet_string(V3, [4]), %%------------------------------------------------- %% attribute serialNumber(4) with type INTEGER %%------------------------------------------------- [V4|Tlv5] = Tlv4, Term4 = decode_integer(V4, [2]), case Tlv5 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv5}}}) % extra fields not allowed end, Res1 = {'CertID',Term1,Term2,Term3,Term4}, Res1. %%================================ %% CertStatus %%================================ enc_CertStatus(Val) -> enc_CertStatus(Val, []). enc_CertStatus(Val, TagIn) -> {EncBytes,EncLen} = case element(1,Val) of good -> encode_null(element(2,Val), [<<128>>]); revoked -> 'enc_RevokedInfo'(element(2,Val), [<<161>>]); unknown -> encode_null(element(2,Val), [<<130>>]); Else -> exit({error,{asn1,{invalid_choice_type,Else}}}) end, encode_tags(TagIn, EncBytes, EncLen). dec_CertStatus(Tlv) -> dec_CertStatus(Tlv, []). dec_CertStatus(Tlv, TagIn) -> Tlv1 = match_tags(Tlv, TagIn), case (case Tlv1 of [CtempTlv1] -> CtempTlv1; _ -> Tlv1 end) of %% 'good' {131072, V1} -> {good, decode_null(V1, [])}; %% 'revoked' {131073, V1} -> {revoked, 'dec_RevokedInfo'(V1, [])}; %% 'unknown' {131074, V1} -> {unknown, decode_null(V1, [])}; Else -> exit({error,{asn1,{invalid_choice_tag,Else}}}) end . %%================================ %% RevokedInfo %%================================ enc_RevokedInfo(Val) -> enc_RevokedInfo(Val, [<<48>>]). enc_RevokedInfo(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute revocationTime(1) with type GeneralizedTime %%------------------------------------------------- {EncBytes1,EncLen1} = encode_restricted_string(Cindex1, [<<24>>]), %%------------------------------------------------- %% attribute revocationReason(2) with type ENUMERATED OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> case Cindex2 of unspecified -> encode_tags([<<10>>,<<160>>], [0], 1); keyCompromise -> encode_tags([<<10>>,<<160>>], [1], 1); cACompromise -> encode_tags([<<10>>,<<160>>], [2], 1); affiliationChanged -> encode_tags([<<10>>,<<160>>], [3], 1); superseded -> encode_tags([<<10>>,<<160>>], [4], 1); cessationOfOperation -> encode_tags([<<10>>,<<160>>], [5], 1); certificateHold -> encode_tags([<<10>>,<<160>>], [6], 1); removeFromCRL -> encode_tags([<<10>>,<<160>>], [8], 1); Enumval2 -> exit({error,{asn1, {enumerated_not_in_range,Enumval2}}}) end end, BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_RevokedInfo(Tlv) -> dec_RevokedInfo(Tlv, [16]). dec_RevokedInfo(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute revocationTime(1) with type GeneralizedTime %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = begin binary_to_list(decode_restricted_string(V1, [24])) end , %%------------------------------------------------- %% attribute revocationReason(2) with type ENUMERATED OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [{131072,V2}|TempTlv3] -> {case decode_integer(V2, [10]) of 0 -> unspecified; 1 -> keyCompromise; 2 -> cACompromise; 3 -> affiliationChanged; 4 -> superseded; 5 -> cessationOfOperation; 6 -> certificateHold; 8 -> removeFromCRL; Default1 -> exit({error,{asn1,{illegal_enumerated,Default1}}}) end, TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'RevokedInfo',Term1,Term2}, Res1. %%================================ %% SingleResponse %%================================ enc_SingleResponse(Val) -> enc_SingleResponse(Val, [<<48>>]). enc_SingleResponse(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3,Cindex4,Cindex5} = Val, %%------------------------------------------------- %% attribute certID(1) External KEP:CertID %%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_CertID'(Cindex1, [<<48>>]), %%------------------------------------------------- %% attribute certStatus(2) External KEP:CertStatus %%------------------------------------------------- {EncBytes2,EncLen2} = 'enc_CertStatus'(Cindex2, []), %%------------------------------------------------- %% attribute thisUpdate(3) with type GeneralizedTime %%------------------------------------------------- {EncBytes3,EncLen3} = encode_restricted_string(Cindex3, [<<24>>]), %%------------------------------------------------- %% attribute nextUpdate(4) with type GeneralizedTime OPTIONAL %%------------------------------------------------- {EncBytes4,EncLen4} = case Cindex4 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_restricted_string(Cindex4, [<<24>>,<<160>>]) end, %%------------------------------------------------- %% attribute singleExtensions(5) External AuthenticationFramework:Extensions OPTIONAL %%------------------------------------------------- {EncBytes5,EncLen5} = case Cindex5 of asn1_NOVALUE -> {<<>>,0}; _ -> 'AuthenticationFramework':'enc_Extensions'(Cindex5, [<<48>>,<<161>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_SingleResponse(Tlv) -> dec_SingleResponse(Tlv, [16]). dec_SingleResponse(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute certID(1) External KEP:CertID %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'dec_CertID'(V1, [16]), %%------------------------------------------------- %% attribute certStatus(2) External KEP:CertStatus %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = 'dec_CertStatus'(V2, []), %%------------------------------------------------- %% attribute thisUpdate(3) with type GeneralizedTime %%------------------------------------------------- [V3|Tlv4] = Tlv3, Term3 = begin binary_to_list(decode_restricted_string(V3, [24])) end , %%------------------------------------------------- %% attribute nextUpdate(4) with type GeneralizedTime OPTIONAL %%------------------------------------------------- {Term4,Tlv5} = case Tlv4 of [{131072,V4}|TempTlv5] -> {begin binary_to_list(decode_restricted_string(V4, [24])) end , TempTlv5}; _ -> { asn1_NOVALUE, Tlv4} end, %%------------------------------------------------- %% attribute singleExtensions(5) External AuthenticationFramework:Extensions OPTIONAL %%------------------------------------------------- {Term5,Tlv6} = case Tlv5 of [{131073,V5}|TempTlv6] -> {'AuthenticationFramework':'dec_Extensions'(V5, [16]), TempTlv6}; _ -> { asn1_NOVALUE, Tlv5} end, case Tlv6 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv6}}}) % extra fields not allowed end, Res1 = {'SingleResponse',Term1,Term2,Term3,Term4,Term5}, Res1. %%================================ %% RevocationValues %%================================ enc_RevocationValues(Val) -> enc_RevocationValues(Val, [<<48>>]). enc_RevocationValues(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3} = Val, %%------------------------------------------------- %% attribute crlVals(1) with type SEQUENCE OF OPTIONAL %%------------------------------------------------- {EncBytes1,EncLen1} = case Cindex1 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_RevocationValues_crlVals'(Cindex1, [<<160>>]) end, %%------------------------------------------------- %% attribute ocspVals(2) with type SEQUENCE OF OPTIONAL %%------------------------------------------------- {EncBytes2,EncLen2} = case Cindex2 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_RevocationValues_ocspVals'(Cindex2, [<<161>>]) end, %%------------------------------------------------- %% attribute otherRevVals(3) External KEP:OtherRevVals OPTIONAL %%------------------------------------------------- {EncBytes3,EncLen3} = case Cindex3 of asn1_NOVALUE -> {<<>>,0}; _ -> 'enc_OtherRevVals'(Cindex3, [<<162>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3], LenSoFar = EncLen1 + EncLen2 + EncLen3, encode_tags(TagIn, BytesSoFar, LenSoFar). %%================================ %% RevocationValues_crlVals %%================================ enc_RevocationValues_crlVals(Val, TagIn) -> {EncBytes,EncLen} = 'enc_RevocationValues_crlVals_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_RevocationValues_crlVals_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_RevocationValues_crlVals_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'AuthenticationFramework':'enc_CertificateList'(H, [<<48>>]), 'enc_RevocationValues_crlVals_components'(T,[EncBytes|AccBytes], AccLen + EncLen). %%================================ %% RevocationValues_ocspVals %%================================ enc_RevocationValues_ocspVals(Val, TagIn) -> {EncBytes,EncLen} = 'enc_RevocationValues_ocspVals_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_RevocationValues_ocspVals_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_RevocationValues_ocspVals_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_BasicOCSPResponse'(H, [<<48>>]), 'enc_RevocationValues_ocspVals_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_RevocationValues(Tlv) -> dec_RevocationValues(Tlv, [16]). dec_RevocationValues(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute crlVals(1) with type SEQUENCE OF OPTIONAL %%------------------------------------------------- {Term1,Tlv2} = case Tlv1 of [{131072,V1}|TempTlv2] -> {'dec_RevocationValues_crlVals'(V1, []), TempTlv2}; _ -> { asn1_NOVALUE, Tlv1} end, %%------------------------------------------------- %% attribute ocspVals(2) with type SEQUENCE OF OPTIONAL %%------------------------------------------------- {Term2,Tlv3} = case Tlv2 of [{131073,V2}|TempTlv3] -> {'dec_RevocationValues_ocspVals'(V2, []), TempTlv3}; _ -> { asn1_NOVALUE, Tlv2} end, %%------------------------------------------------- %% attribute otherRevVals(3) External KEP:OtherRevVals OPTIONAL %%------------------------------------------------- {Term3,Tlv4} = case Tlv3 of [{131074,V3}|TempTlv4] -> {'dec_OtherRevVals'(V3, []), TempTlv4}; _ -> { asn1_NOVALUE, Tlv3} end, case Tlv4 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv4}}}) % extra fields not allowed end, Res1 = {'RevocationValues',Term1,Term2,Term3}, Res1. 'dec_RevocationValues_crlVals'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['AuthenticationFramework':'dec_CertificateList'(V1, [16]) || V1 <- Tlv1]. 'dec_RevocationValues_ocspVals'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_BasicOCSPResponse'(V1, [16]) || V1 <- Tlv1]. %%================================ %% OtherRevValType %%================================ enc_OtherRevValType(Val) -> enc_OtherRevValType(Val, [<<6>>]). enc_OtherRevValType(Val, TagIn) -> encode_object_identifier(Val, TagIn). dec_OtherRevValType(Tlv) -> dec_OtherRevValType(Tlv, [6]). dec_OtherRevValType(Tlv, TagIn) -> decode_object_identifier(Tlv, TagIn). %%================================ %% OtherRevVals %%================================ enc_OtherRevVals(Val) -> enc_OtherRevVals(Val, [<<48>>]). enc_OtherRevVals(Val, TagIn) -> {_,Cindex1} = Val, %%------------------------------------------------- %% attribute otherRevValType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_object_identifier(Cindex1, [<<6>>]), BytesSoFar = [EncBytes1], LenSoFar = EncLen1, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_OtherRevVals(Tlv) -> dec_OtherRevVals(Tlv, [16]). dec_OtherRevVals(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute otherRevValType(1) with type OBJECT IDENTIFIER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_object_identifier(V1, [6]), case Tlv2 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv2}}}) % extra fields not allowed end, Res1 = {'OtherRevVals',Term1}, Res1. %%================================ %% CRLListID %%================================ enc_CRLListID(Val) -> enc_CRLListID(Val, [<<48>>]). enc_CRLListID(Val, TagIn) -> {_,Cindex1} = Val, %%------------------------------------------------- %% attribute crls(1) with type SEQUENCE OF %%------------------------------------------------- {EncBytes1,EncLen1} = 'enc_CRLListID_crls'(Cindex1, [<<48>>]), BytesSoFar = [EncBytes1], LenSoFar = EncLen1, encode_tags(TagIn, BytesSoFar, LenSoFar). %%================================ %% CRLListID_crls %%================================ enc_CRLListID_crls(Val, TagIn) -> {EncBytes,EncLen} = 'enc_CRLListID_crls_components'(Val,[],0), encode_tags(TagIn, EncBytes, EncLen). 'enc_CRLListID_crls_components'([], AccBytes, AccLen) -> {lists:reverse(AccBytes),AccLen}; 'enc_CRLListID_crls_components'([H|T],AccBytes, AccLen) -> {EncBytes,EncLen} = 'enc_CrlValidatedID'(H, [<<48>>]), 'enc_CRLListID_crls_components'(T,[EncBytes|AccBytes], AccLen + EncLen). dec_CRLListID(Tlv) -> dec_CRLListID(Tlv, [16]). dec_CRLListID(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute crls(1) with type SEQUENCE OF %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'dec_CRLListID_crls'(V1, [16]), case Tlv2 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv2}}}) % extra fields not allowed end, Res1 = {'CRLListID',Term1}, Res1. 'dec_CRLListID_crls'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), ['dec_CrlValidatedID'(V1, [16]) || V1 <- Tlv1]. %%================================ %% MessageImprint %%================================ enc_MessageImprint(Val) -> enc_MessageImprint(Val, [<<48>>]). enc_MessageImprint(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute hashAlgorithm(1) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- {EncBytes1,EncLen1} = 'AuthenticationFramework':'enc_AlgorithmIdentifier'(Cindex1, [<<48>>]), %%------------------------------------------------- %% attribute hashedMessage(2) with type OCTET STRING %%------------------------------------------------- {EncBytes2,EncLen2} = encode_restricted_string(Cindex2, [<<4>>]), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_MessageImprint(Tlv) -> dec_MessageImprint(Tlv, [16]). dec_MessageImprint(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute hashAlgorithm(1) External AuthenticationFramework:AlgorithmIdentifier %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = 'AuthenticationFramework':'dec_AlgorithmIdentifier'(V1, [16]), %%------------------------------------------------- %% attribute hashedMessage(2) with type OCTET STRING %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_octet_string(V2, [4]), case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'MessageImprint',Term1,Term2}, Res1. %%================================ %% TimeStampReq %%================================ enc_TimeStampReq(Val) -> enc_TimeStampReq(Val, [<<48>>]). enc_TimeStampReq(Val, TagIn) -> {_,Cindex1,Cindex2,Cindex3,Cindex4,Cindex5,Cindex6} = Val, %%------------------------------------------------- %% attribute version(1) with type INTEGER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_integer(Cindex1, [{v1,1}], [<<2>>]), %%------------------------------------------------- %% attribute messageImprint(2) External KEP:MessageImprint %%------------------------------------------------- {EncBytes2,EncLen2} = 'enc_MessageImprint'(Cindex2, [<<48>>]), %%------------------------------------------------- %% attribute reqPolicy(3) with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {EncBytes3,EncLen3} = case Cindex3 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_object_identifier(Cindex3, [<<6>>]) end, %%------------------------------------------------- %% attribute nonce(4) with type INTEGER OPTIONAL %%------------------------------------------------- {EncBytes4,EncLen4} = case Cindex4 of asn1_NOVALUE -> {<<>>,0}; _ -> encode_integer(Cindex4, [<<2>>]) end, %%------------------------------------------------- %% attribute certReq(5) with type BOOLEAN DEFAULT = false %%------------------------------------------------- {EncBytes5,EncLen5} = case Cindex5 of asn1_DEFAULT -> {<<>>,0}; _ when Cindex5 =:= false -> {<<>>,0}; _ -> encode_boolean(Cindex5, [<<1>>]) end, %%------------------------------------------------- %% attribute extensions(6) External AuthenticationFramework:Extensions OPTIONAL %%------------------------------------------------- {EncBytes6,EncLen6} = case Cindex6 of asn1_NOVALUE -> {<<>>,0}; _ -> 'AuthenticationFramework':'enc_Extensions'(Cindex6, [<<160>>]) end, BytesSoFar = [EncBytes1, EncBytes2, EncBytes3, EncBytes4, EncBytes5, EncBytes6], LenSoFar = EncLen1 + EncLen2 + EncLen3 + EncLen4 + EncLen5 + EncLen6, encode_tags(TagIn, BytesSoFar, LenSoFar). dec_TimeStampReq(Tlv) -> dec_TimeStampReq(Tlv, [16]). dec_TimeStampReq(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute version(1) with type INTEGER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = begin Val1 = decode_integer(V1, [2]), number2name(Val1, [{v1,1}]) end , %%------------------------------------------------- %% attribute messageImprint(2) External KEP:MessageImprint %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = 'dec_MessageImprint'(V2, [16]), %%------------------------------------------------- %% attribute reqPolicy(3) with type OBJECT IDENTIFIER OPTIONAL %%------------------------------------------------- {Term3,Tlv4} = case Tlv3 of [{6,V3}|TempTlv4] -> {decode_object_identifier(V3, []), TempTlv4}; _ -> { asn1_NOVALUE, Tlv3} end, %%------------------------------------------------- %% attribute nonce(4) with type INTEGER OPTIONAL %%------------------------------------------------- {Term4,Tlv5} = case Tlv4 of [{2,V4}|TempTlv5] -> {decode_integer(V4, []), TempTlv5}; _ -> { asn1_NOVALUE, Tlv4} end, %%------------------------------------------------- %% attribute certReq(5) with type BOOLEAN DEFAULT = false %%------------------------------------------------- {Term5,Tlv6} = case Tlv5 of [{1,V5}|TempTlv6] -> {decode_boolean(V5, []), TempTlv6}; _ -> {false,Tlv5} end, %%------------------------------------------------- %% attribute extensions(6) External AuthenticationFramework:Extensions OPTIONAL %%------------------------------------------------- {Term6,Tlv7} = case Tlv6 of [{131072,V6}|TempTlv7] -> {'AuthenticationFramework':'dec_Extensions'(V6, []), TempTlv7}; _ -> { asn1_NOVALUE, Tlv6} end, case Tlv7 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv7}}}) % extra fields not allowed end, Res1 = {'TimeStampReq',Term1,Term2,Term3,Term4,Term5,Term6}, Res1. %%================================ %% INSTANCE OF %%================================ 'enc_INSTANCE OF'(Val) -> 'enc_INSTANCE OF'(Val, [<<40>>]). 'enc_INSTANCE OF'(Val, TagIn) -> {_,Cindex1,Cindex2} = Val, %%------------------------------------------------- %% attribute type-id(1) with type OBJECT IDENTIFIER %%------------------------------------------------- {EncBytes1,EncLen1} = encode_object_identifier(Cindex1, [<<6>>]), %%------------------------------------------------- %% attribute value(2) with type ASN1_OPEN_TYPE %%------------------------------------------------- {EncBytes2,EncLen2} = encode_open_type(Cindex2, [<<160>>]), BytesSoFar = [EncBytes1, EncBytes2], LenSoFar = EncLen1 + EncLen2, encode_tags(TagIn, BytesSoFar, LenSoFar). 'dec_INSTANCE OF'(Tlv) -> 'dec_INSTANCE OF'(Tlv, [8]). 'dec_INSTANCE OF'(Tlv, TagIn) -> %%------------------------------------------------- %% decode tag and length %%------------------------------------------------- Tlv1 = match_tags(Tlv, TagIn), %%------------------------------------------------- %% attribute type-id(1) with type OBJECT IDENTIFIER %%------------------------------------------------- [V1|Tlv2] = Tlv1, Term1 = decode_object_identifier(V1, [6]), %%------------------------------------------------- %% attribute value(2) with type ASN1_OPEN_TYPE %%------------------------------------------------- [V2|Tlv3] = Tlv2, Term2 = decode_open_type_as_binary(V2, [131072]), case Tlv3 of [] -> true;_ -> exit({error,{asn1, {unexpected,Tlv3}}}) % extra fields not allowed end, Res1 = {'INSTANCE OF',Term1,Term2}, Res1. 'id-data'() -> {1,2,840,113549,1,7,1}. 'id-signedData'() -> {1,2,840,113549,1,7,2}. 'id-contentType'() -> {1,2,840,113549,1,9,3}. 'id-messageDigest'() -> {1,2,840,113549,1,9,4}. 'id-signingTime'() -> {1,2,840,113549,1,9,5}. 'id-aa-signTSToken'() -> {1,2,840,113549,1,9,16,2,14}. 'id-aa-ets-sigPolicyId'() -> {1,2,840,113549,1,9,16,2,15}. 'id-aa-ets-ContentTS'() -> {1,2,840,113549,1,9,16,2,20}. 'id-aa-ets-certRefs'() -> {1,2,840,113549,1,9,16,2,21}. 'id-aa-ets-revocationRefs'() -> {1,2,840,113549,1,9,16,2,22}. 'id-aa-ets-certValues'() -> {1,2,840,113549,1,9,16,2,23}. 'id-aa-ets-revoValues'() -> {1,2,840,113549,1,9,16,2,24}. 'id-aa-signingCertV2'() -> {1,2,840,113549,1,9,16,2,47}. 'id-spq-ets-uri'() -> {1,2,840,113549,1,9,16,5,1}. 'id-spq-ets-unotice'() -> {1,2,840,113549,1,9,16,5,2}. gost34311() -> {1,2,804,2,1,1,1,1,2,1}. %%% %%% 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_BMP_string(Buffer, Tags) -> Bin = match_and_collect(Buffer, Tags), mk_BMP_string(binary_to_list(Bin)). decode_UTF8_string(Tlv, TagsIn) -> Val = match_tags(Tlv, TagsIn), case Val of [_ | _] = PartList -> collect_parts(PartList); Bin -> Bin end. decode_boolean(Tlv, TagIn) -> Val = match_tags(Tlv, TagIn), case Val of <<0:8>> -> false; <<_:8>> -> true; _ -> exit({error, {asn1, {decode_boolean, Val}}}) end. decode_integer(Tlv, TagIn) -> Bin = match_tags(Tlv, TagIn), Len = byte_size(Bin), <> = Bin, Int. decode_native_bit_string(Buffer, Tags) -> case match_and_collect(Buffer, Tags) of <<0>> -> <<>>; <> -> Size = bit_size(Bits) - Unused, <> = 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_octet_string(Tlv, TagsIn) -> Bin = match_and_collect(Tlv, TagsIn), binary:copy(Bin). decode_open_type_as_binary(Tlv, TagIn) -> ber_encode(match_tags(Tlv, TagIn)). decode_restricted_string(Tlv, TagsIn) -> match_and_collect(Tlv, TagsIn). 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_UTF8_string(UTF8String, TagIn) when is_binary(UTF8String) -> encode_tags(TagIn, UTF8String, byte_size(UTF8String)); encode_UTF8_string(UTF8String, TagIn) -> encode_tags(TagIn, UTF8String, length(UTF8String)). encode_boolean(true, TagIn) -> encode_tags(TagIn, [255], 1); encode_boolean(false, TagIn) -> encode_tags(TagIn, [0], 1); encode_boolean(X, _) -> exit({error, {asn1, {encode_boolean, X}}}). 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_null(_Val, TagIn) -> encode_tags(TagIn, [], 0). 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)). 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). number2name(Int, NamedNumberList) -> case lists:keyfind(Int, 2, NamedNumberList) of {NamedVal, _} -> NamedVal; _ -> Int end.