UNPKG

@wildboar/pkcs

Version:
201 lines (200 loc) 7.48 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_CertificateRevocationLists, _encode_CertificateRevocationLists, } from "../CryptographicMessageSyntax/CertificateRevocationLists.ta.mjs"; import { _decode_CertificateSet, _encode_CertificateSet, } from "../CryptographicMessageSyntax/CertificateSet.ta.mjs"; import { _decode_CMSVersion, _encode_CMSVersion, } from "../CryptographicMessageSyntax/CMSVersion.ta.mjs"; import { _decode_DigestAlgorithmIdentifiers, _encode_DigestAlgorithmIdentifiers, } from "../CryptographicMessageSyntax/DigestAlgorithmIdentifiers.ta.mjs"; import { _decode_EncapsulatedContentInfo, _encode_EncapsulatedContentInfo, } from "../CryptographicMessageSyntax/EncapsulatedContentInfo.ta.mjs"; import { _decode_SignerInfos, _encode_SignerInfos, } from "../CryptographicMessageSyntax/SignerInfos.ta.mjs"; /** * @summary SignedData * @description * * ### ASN.1 Definition: * * ```asn1 * SignedData ::= SEQUENCE { * version CMSVersion, * digestAlgorithms DigestAlgorithmIdentifiers, * encapContentInfo EncapsulatedContentInfo, * certificates [0] IMPLICIT CertificateSet OPTIONAL, * crls [1] IMPLICIT CertificateRevocationLists OPTIONAL, * signerInfos SignerInfos * } * ``` * */ export class SignedData { version; digestAlgorithms; encapContentInfo; certificates; crls; signerInfos; constructor( /** * @summary `version`. * @public * @readonly */ version, /** * @summary `digestAlgorithms`. * @public * @readonly */ digestAlgorithms, /** * @summary `encapContentInfo`. * @public * @readonly */ encapContentInfo, /** * @summary `certificates`. * @public * @readonly */ certificates, /** * @summary `crls`. * @public * @readonly */ crls, /** * @summary `signerInfos`. * @public * @readonly */ signerInfos) { this.version = version; this.digestAlgorithms = digestAlgorithms; this.encapContentInfo = encapContentInfo; this.certificates = certificates; this.crls = crls; this.signerInfos = signerInfos; } /** * @summary Restructures an object into a SignedData * @description * * This takes an `object` and converts it to a `SignedData`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `SignedData`. * @returns {SignedData} */ static _from_object(_o) { return new SignedData(_o.version, _o.digestAlgorithms, _o.encapContentInfo, _o.certificates, _o.crls, _o.signerInfos); } } /** * @summary The Leading Root Component Types of SignedData * @description * * This is an array of `ComponentSpec`s that define how to decode the leading root component type list of a SET or SEQUENCE. * * @constant */ export const _root_component_type_list_1_spec_for_SignedData = [ new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("digestAlgorithms", false, $.hasTag(_TagClass.universal, 17)), new $.ComponentSpec("encapContentInfo", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("certificates", true, $.hasTag(_TagClass.context, 0)), new $.ComponentSpec("crls", true, $.hasTag(_TagClass.context, 1)), new $.ComponentSpec("signerInfos", false, $.hasTag(_TagClass.universal, 17)), ]; /** * @summary The Trailing Root Component Types of SignedData * @description * * This is an array of `ComponentSpec`s that define how to decode the trailing root component type list of a SET or SEQUENCE. * * @constant */ export const _root_component_type_list_2_spec_for_SignedData = []; /** * @summary The Extension Addition Component Types of SignedData * @description * * This is an array of `ComponentSpec`s that define how to decode the extension addition component type list of a SET or SEQUENCE. * * @constant */ export const _extension_additions_list_spec_for_SignedData = []; let _cached_decoder_for_SignedData = null; /** * @summary Decodes an ASN.1 element into a(n) SignedData * @function * @param {_Element} el The element being decoded. * @returns {SignedData} The decoded data structure. */ export function _decode_SignedData(el) { if (!_cached_decoder_for_SignedData) { _cached_decoder_for_SignedData = function (el) { let version; let digestAlgorithms; let encapContentInfo; let certificates; let crls; let signerInfos; const callbacks = { version: (_el) => { version = _decode_CMSVersion(_el); }, digestAlgorithms: (_el) => { digestAlgorithms = _decode_DigestAlgorithmIdentifiers(_el); }, encapContentInfo: (_el) => { encapContentInfo = _decode_EncapsulatedContentInfo(_el); }, certificates: (_el) => { certificates = $._decode_implicit(() => _decode_CertificateSet)(_el); }, crls: (_el) => { crls = $._decode_implicit(() => _decode_CertificateRevocationLists)(_el); }, signerInfos: (_el) => { signerInfos = _decode_SignerInfos(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_SignedData, _extension_additions_list_spec_for_SignedData, _root_component_type_list_2_spec_for_SignedData, undefined); return new SignedData(version, digestAlgorithms, encapContentInfo, certificates, crls, signerInfos); }; } return _cached_decoder_for_SignedData(el); } let _cached_encoder_for_SignedData = null; /** * @summary Encodes a(n) SignedData into an ASN.1 Element. * @function * @param value The element being encoded. * @param elGetter A function that can be used to get new ASN.1 elements. * @returns {_Element} The SignedData, encoded as an ASN.1 Element. */ export function _encode_SignedData(value, elGetter) { if (!_cached_encoder_for_SignedData) { _cached_encoder_for_SignedData = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_CMSVersion(value.version, $.BER), /* REQUIRED */ _encode_DigestAlgorithmIdentifiers(value.digestAlgorithms, $.BER), /* REQUIRED */ _encode_EncapsulatedContentInfo(value.encapContentInfo, $.BER), /* IF_ABSENT */ value.certificates === undefined ? undefined : $._encode_implicit(_TagClass.context, 0, () => _encode_CertificateSet, $.BER)(value.certificates, $.BER), /* IF_ABSENT */ value.crls === undefined ? undefined : $._encode_implicit(_TagClass.context, 1, () => _encode_CertificateRevocationLists, $.BER)(value.crls, $.BER), /* REQUIRED */ _encode_SignerInfos(value.signerInfos, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_SignedData(value, elGetter); } /* eslint-enable */