UNPKG

@wildboar/pkcs

Version:
218 lines (217 loc) 8.56 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_Attributes, _encode_Attributes, } from "../PKCS7/Attributes.ta.mjs"; import { _decode_DigestAlgorithmIdentifier, _encode_DigestAlgorithmIdentifier, } from "../PKCS7/DigestAlgorithmIdentifier.ta.mjs"; import { _decode_DigestEncryptionAlgorithmIdentifier, _encode_DigestEncryptionAlgorithmIdentifier, } from "../PKCS7/DigestEncryptionAlgorithmIdentifier.ta.mjs"; import { _decode_EncryptedDigest, _encode_EncryptedDigest, } from "../PKCS7/EncryptedDigest.ta.mjs"; import { _decode_SignerIdentifier, _encode_SignerIdentifier, } from "../PKCS7/SignerIdentifier.ta.mjs"; import { _decode_Version, _encode_Version } from "../PKCS7/Version.ta.mjs"; /** * @summary SignerInfo * @description * * ### ASN.1 Definition: * * ```asn1 * SignerInfo ::= SEQUENCE { * version Version, * signerIdentifier SignerIdentifier, * digestAlgorithm DigestAlgorithmIdentifier, * authenticatedAttributes [0] Attributes OPTIONAL, * digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier, * encryptedDigest EncryptedDigest, * unauthenticatedAttributes [1] Attributes OPTIONAL * } * ``` * */ export class SignerInfo { version; signerIdentifier; digestAlgorithm; authenticatedAttributes; digestEncryptionAlgorithm; encryptedDigest; unauthenticatedAttributes; constructor( /** * @summary `version`. * @public * @readonly */ version, /** * @summary `signerIdentifier`. * @public * @readonly */ signerIdentifier, /** * @summary `digestAlgorithm`. * @public * @readonly */ digestAlgorithm, /** * @summary `authenticatedAttributes`. * @public * @readonly */ authenticatedAttributes, /** * @summary `digestEncryptionAlgorithm`. * @public * @readonly */ digestEncryptionAlgorithm, /** * @summary `encryptedDigest`. * @public * @readonly */ encryptedDigest, /** * @summary `unauthenticatedAttributes`. * @public * @readonly */ unauthenticatedAttributes) { this.version = version; this.signerIdentifier = signerIdentifier; this.digestAlgorithm = digestAlgorithm; this.authenticatedAttributes = authenticatedAttributes; this.digestEncryptionAlgorithm = digestEncryptionAlgorithm; this.encryptedDigest = encryptedDigest; this.unauthenticatedAttributes = unauthenticatedAttributes; } /** * @summary Restructures an object into a SignerInfo * @description * * This takes an `object` and converts it to a `SignerInfo`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `SignerInfo`. * @returns {SignerInfo} */ static _from_object(_o) { return new SignerInfo(_o.version, _o.signerIdentifier, _o.digestAlgorithm, _o.authenticatedAttributes, _o.digestEncryptionAlgorithm, _o.encryptedDigest, _o.unauthenticatedAttributes); } } /** * @summary The Leading Root Component Types of SignerInfo * @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_SignerInfo = [ new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("signerIdentifier", false, $.hasAnyTag), new $.ComponentSpec("digestAlgorithm", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("authenticatedAttributes", true, $.hasTag(_TagClass.context, 0)), new $.ComponentSpec("digestEncryptionAlgorithm", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("encryptedDigest", false, $.hasTag(_TagClass.universal, 4)), new $.ComponentSpec("unauthenticatedAttributes", true, $.hasTag(_TagClass.context, 1)), ]; /** * @summary The Trailing Root Component Types of SignerInfo * @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_SignerInfo = []; /** * @summary The Extension Addition Component Types of SignerInfo * @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_SignerInfo = []; let _cached_decoder_for_SignerInfo = null; /** * @summary Decodes an ASN.1 element into a(n) SignerInfo * @function * @param {_Element} el The element being decoded. * @returns {SignerInfo} The decoded data structure. */ export function _decode_SignerInfo(el) { if (!_cached_decoder_for_SignerInfo) { _cached_decoder_for_SignerInfo = function (el) { let version; let signerIdentifier; let digestAlgorithm; let authenticatedAttributes; let digestEncryptionAlgorithm; let encryptedDigest; let unauthenticatedAttributes; const callbacks = { version: (_el) => { version = _decode_Version(_el); }, signerIdentifier: (_el) => { signerIdentifier = _decode_SignerIdentifier(_el); }, digestAlgorithm: (_el) => { digestAlgorithm = _decode_DigestAlgorithmIdentifier(_el); }, authenticatedAttributes: (_el) => { authenticatedAttributes = $._decode_implicit(() => _decode_Attributes)(_el); }, digestEncryptionAlgorithm: (_el) => { digestEncryptionAlgorithm = _decode_DigestEncryptionAlgorithmIdentifier(_el); }, encryptedDigest: (_el) => { encryptedDigest = _decode_EncryptedDigest(_el); }, unauthenticatedAttributes: (_el) => { unauthenticatedAttributes = $._decode_implicit(() => _decode_Attributes)(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_SignerInfo, _extension_additions_list_spec_for_SignerInfo, _root_component_type_list_2_spec_for_SignerInfo, undefined); return new SignerInfo(version, signerIdentifier, digestAlgorithm, authenticatedAttributes, digestEncryptionAlgorithm, encryptedDigest, unauthenticatedAttributes); }; } return _cached_decoder_for_SignerInfo(el); } let _cached_encoder_for_SignerInfo = null; /** * @summary Encodes a(n) SignerInfo 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 SignerInfo, encoded as an ASN.1 Element. */ export function _encode_SignerInfo(value, elGetter) { if (!_cached_encoder_for_SignerInfo) { _cached_encoder_for_SignerInfo = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_Version(value.version, $.BER), /* REQUIRED */ _encode_SignerIdentifier(value.signerIdentifier, $.BER), /* REQUIRED */ _encode_DigestAlgorithmIdentifier(value.digestAlgorithm, $.BER), /* IF_ABSENT */ value.authenticatedAttributes === undefined ? undefined : $._encode_implicit(_TagClass.context, 0, () => _encode_Attributes, $.BER)(value.authenticatedAttributes, $.BER), /* REQUIRED */ _encode_DigestEncryptionAlgorithmIdentifier(value.digestEncryptionAlgorithm, $.BER), /* REQUIRED */ _encode_EncryptedDigest(value.encryptedDigest, $.BER), /* IF_ABSENT */ value.unauthenticatedAttributes === undefined ? undefined : $._encode_implicit(_TagClass.context, 1, () => _encode_Attributes, $.BER)(value.unauthenticatedAttributes, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_SignerInfo(value, elGetter); } /* eslint-enable */