UNPKG

@wildboar/pkcs

Version:
185 lines (184 loc) 7.04 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_EncryptedContentInfo, _encode_EncryptedContentInfo, } from "../CryptographicMessageSyntax/EncryptedContentInfo.ta.mjs"; import { _decode_OriginatorInfo, _encode_OriginatorInfo, } from "../CryptographicMessageSyntax/OriginatorInfo.ta.mjs"; import { _decode_RecipientInfos, _encode_RecipientInfos, } from "../CryptographicMessageSyntax/RecipientInfos.ta.mjs"; import { _decode_UnprotectedAttributes, _encode_UnprotectedAttributes, } from "../CryptographicMessageSyntax/UnprotectedAttributes.ta.mjs"; /** * @summary EnvelopedData * @description * * ### ASN.1 Definition: * * ```asn1 * EnvelopedData ::= SEQUENCE { * version CMSVersion, * originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL, * recipientInfos RecipientInfos, * encryptedContentInfo EncryptedContentInfo, * unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL * } * ``` * */ export class EnvelopedData { version; originatorInfo; recipientInfos; encryptedContentInfo; unprotectedAttrs; constructor( /** * @summary `version`. * @public * @readonly */ version, /** * @summary `originatorInfo`. * @public * @readonly */ originatorInfo, /** * @summary `recipientInfos`. * @public * @readonly */ recipientInfos, /** * @summary `encryptedContentInfo`. * @public * @readonly */ encryptedContentInfo, /** * @summary `unprotectedAttrs`. * @public * @readonly */ unprotectedAttrs) { this.version = version; this.originatorInfo = originatorInfo; this.recipientInfos = recipientInfos; this.encryptedContentInfo = encryptedContentInfo; this.unprotectedAttrs = unprotectedAttrs; } /** * @summary Restructures an object into a EnvelopedData * @description * * This takes an `object` and converts it to a `EnvelopedData`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `EnvelopedData`. * @returns {EnvelopedData} */ static _from_object(_o) { return new EnvelopedData(_o.version, _o.originatorInfo, _o.recipientInfos, _o.encryptedContentInfo, _o.unprotectedAttrs); } } /** * @summary The Leading Root Component Types of EnvelopedData * @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_EnvelopedData = [ new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("originatorInfo", true, $.hasTag(_TagClass.context, 0)), new $.ComponentSpec("recipientInfos", false, $.hasTag(_TagClass.universal, 17)), new $.ComponentSpec("encryptedContentInfo", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("unprotectedAttrs", true, $.hasTag(_TagClass.context, 1)), ]; /** * @summary The Trailing Root Component Types of EnvelopedData * @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_EnvelopedData = []; /** * @summary The Extension Addition Component Types of EnvelopedData * @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_EnvelopedData = []; let _cached_decoder_for_EnvelopedData = null; /** * @summary Decodes an ASN.1 element into a(n) EnvelopedData * @function * @param {_Element} el The element being decoded. * @returns {EnvelopedData} The decoded data structure. */ export function _decode_EnvelopedData(el) { if (!_cached_decoder_for_EnvelopedData) { _cached_decoder_for_EnvelopedData = function (el) { let version; let originatorInfo; let recipientInfos; let encryptedContentInfo; let unprotectedAttrs; const callbacks = { version: (_el) => { version = _decode_CMSVersion(_el); }, originatorInfo: (_el) => { originatorInfo = $._decode_implicit(() => _decode_OriginatorInfo)(_el); }, recipientInfos: (_el) => { recipientInfos = _decode_RecipientInfos(_el); }, encryptedContentInfo: (_el) => { encryptedContentInfo = _decode_EncryptedContentInfo(_el); }, unprotectedAttrs: (_el) => { unprotectedAttrs = $._decode_implicit(() => _decode_UnprotectedAttributes)(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_EnvelopedData, _extension_additions_list_spec_for_EnvelopedData, _root_component_type_list_2_spec_for_EnvelopedData, undefined); return new EnvelopedData(version, originatorInfo, recipientInfos, encryptedContentInfo, unprotectedAttrs); }; } return _cached_decoder_for_EnvelopedData(el); } let _cached_encoder_for_EnvelopedData = null; /** * @summary Encodes a(n) EnvelopedData 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 EnvelopedData, encoded as an ASN.1 Element. */ export function _encode_EnvelopedData(value, elGetter) { if (!_cached_encoder_for_EnvelopedData) { _cached_encoder_for_EnvelopedData = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_CMSVersion(value.version, $.BER), /* IF_ABSENT */ value.originatorInfo === undefined ? undefined : $._encode_implicit(_TagClass.context, 0, () => _encode_OriginatorInfo, $.BER)(value.originatorInfo, $.BER), /* REQUIRED */ _encode_RecipientInfos(value.recipientInfos, $.BER), /* REQUIRED */ _encode_EncryptedContentInfo(value.encryptedContentInfo, $.BER), /* IF_ABSENT */ value.unprotectedAttrs === undefined ? undefined : $._encode_implicit(_TagClass.context, 1, () => _encode_UnprotectedAttributes, $.BER)(value.unprotectedAttrs, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_EnvelopedData(value, elGetter); } /* eslint-enable */