UNPKG

@wildboar/pkcs

Version:
217 lines (216 loc) 8.14 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_CMSVersion, _encode_CMSVersion, } from "../CryptographicMessageSyntax/CMSVersion.ta.mjs"; import { _decode_DigestAlgorithmIdentifier, _encode_DigestAlgorithmIdentifier, } from "../CryptographicMessageSyntax/DigestAlgorithmIdentifier.ta.mjs"; import { _decode_SignatureAlgorithmIdentifier, _encode_SignatureAlgorithmIdentifier, } from "../CryptographicMessageSyntax/SignatureAlgorithmIdentifier.ta.mjs"; import { _decode_SignatureValue, _encode_SignatureValue, } from "../CryptographicMessageSyntax/SignatureValue.ta.mjs"; import { _decode_SignedAttributes, _encode_SignedAttributes, } from "../CryptographicMessageSyntax/SignedAttributes.ta.mjs"; import { _decode_SignerIdentifier, _encode_SignerIdentifier, } from "../CryptographicMessageSyntax/SignerIdentifier.ta.mjs"; import { _decode_UnsignedAttributes, _encode_UnsignedAttributes, } from "../CryptographicMessageSyntax/UnsignedAttributes.ta.mjs"; /** * @summary SignerInfo * @description * * ### ASN.1 Definition: * * ```asn1 * SignerInfo ::= SEQUENCE { * version CMSVersion, * sid SignerIdentifier, * digestAlgorithm DigestAlgorithmIdentifier, * signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL, * signatureAlgorithm SignatureAlgorithmIdentifier, * signature SignatureValue, * unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL * } * ``` * */ export class SignerInfo { version; sid; digestAlgorithm; signedAttrs; signatureAlgorithm; signature; unsignedAttrs; constructor( /** * @summary `version`. * @public * @readonly */ version, /** * @summary `sid`. * @public * @readonly */ sid, /** * @summary `digestAlgorithm`. * @public * @readonly */ digestAlgorithm, /** * @summary `signedAttrs`. * @public * @readonly */ signedAttrs, /** * @summary `signatureAlgorithm`. * @public * @readonly */ signatureAlgorithm, /** * @summary `signature`. * @public * @readonly */ signature, /** * @summary `unsignedAttrs`. * @public * @readonly */ unsignedAttrs) { this.version = version; this.sid = sid; this.digestAlgorithm = digestAlgorithm; this.signedAttrs = signedAttrs; this.signatureAlgorithm = signatureAlgorithm; this.signature = signature; this.unsignedAttrs = unsignedAttrs; } /** * @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.sid, _o.digestAlgorithm, _o.signedAttrs, _o.signatureAlgorithm, _o.signature, _o.unsignedAttrs); } } /** * @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("sid", false, $.hasAnyTag), new $.ComponentSpec("digestAlgorithm", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("signedAttrs", true, $.hasTag(_TagClass.context, 0)), new $.ComponentSpec("signatureAlgorithm", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("signature", false, $.hasTag(_TagClass.universal, 4)), new $.ComponentSpec("unsignedAttrs", 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 sid; let digestAlgorithm; let signedAttrs; let signatureAlgorithm; let signature; let unsignedAttrs; const callbacks = { version: (_el) => { version = _decode_CMSVersion(_el); }, sid: (_el) => { sid = _decode_SignerIdentifier(_el); }, digestAlgorithm: (_el) => { digestAlgorithm = _decode_DigestAlgorithmIdentifier(_el); }, signedAttrs: (_el) => { signedAttrs = $._decode_implicit(() => _decode_SignedAttributes)(_el); }, signatureAlgorithm: (_el) => { signatureAlgorithm = _decode_SignatureAlgorithmIdentifier(_el); }, signature: (_el) => { signature = _decode_SignatureValue(_el); }, unsignedAttrs: (_el) => { unsignedAttrs = $._decode_implicit(() => _decode_UnsignedAttributes)(_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, sid, digestAlgorithm, signedAttrs, signatureAlgorithm, signature, unsignedAttrs); }; } 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_CMSVersion(value.version, $.BER), /* REQUIRED */ _encode_SignerIdentifier(value.sid, $.BER), /* REQUIRED */ _encode_DigestAlgorithmIdentifier(value.digestAlgorithm, $.BER), /* IF_ABSENT */ value.signedAttrs === undefined ? undefined : $._encode_implicit(_TagClass.context, 0, () => _encode_SignedAttributes, $.BER)(value.signedAttrs, $.BER), /* REQUIRED */ _encode_SignatureAlgorithmIdentifier(value.signatureAlgorithm, $.BER), /* REQUIRED */ _encode_SignatureValue(value.signature, $.BER), /* IF_ABSENT */ value.unsignedAttrs === undefined ? undefined : $._encode_implicit(_TagClass.context, 1, () => _encode_UnsignedAttributes, $.BER)(value.unsignedAttrs, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_SignerInfo(value, elGetter); } /* eslint-enable */