UNPKG

@wildboar/pkcs

Version:
152 lines (151 loc) 5.4 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_EncryptedContentInfo, _encode_EncryptedContentInfo, } from "../PKCS7/EncryptedContentInfo.ta.mjs"; import { _decode_Version, _encode_Version } from "../PKCS7/Version.ta.mjs"; /** * @summary EncryptedData * @description * * ### ASN.1 Definition: * * ```asn1 * EncryptedData ::= SEQUENCE { * version Version, * encryptedContentInfo EncryptedContentInfo, * unprotectedAttributes [1] Attributes OPTIONAL * } * ``` * */ export class EncryptedData { version; encryptedContentInfo; unprotectedAttributes; constructor( /** * @summary `version`. * @public * @readonly */ version, /** * @summary `encryptedContentInfo`. * @public * @readonly */ encryptedContentInfo, /** * @summary `unprotectedAttributes`. * @public * @readonly */ unprotectedAttributes) { this.version = version; this.encryptedContentInfo = encryptedContentInfo; this.unprotectedAttributes = unprotectedAttributes; } /** * @summary Restructures an object into a EncryptedData * @description * * This takes an `object` and converts it to a `EncryptedData`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `EncryptedData`. * @returns {EncryptedData} */ static _from_object(_o) { return new EncryptedData(_o.version, _o.encryptedContentInfo, _o.unprotectedAttributes); } } /** * @summary The Leading Root Component Types of EncryptedData * @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_EncryptedData = [ new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("encryptedContentInfo", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("unprotectedAttributes", true, $.hasTag(_TagClass.context, 1)), ]; /** * @summary The Trailing Root Component Types of EncryptedData * @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_EncryptedData = []; /** * @summary The Extension Addition Component Types of EncryptedData * @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_EncryptedData = []; let _cached_decoder_for_EncryptedData = null; /** * @summary Decodes an ASN.1 element into a(n) EncryptedData * @function * @param {_Element} el The element being decoded. * @returns {EncryptedData} The decoded data structure. */ export function _decode_EncryptedData(el) { if (!_cached_decoder_for_EncryptedData) { _cached_decoder_for_EncryptedData = function (el) { let version; let encryptedContentInfo; let unprotectedAttributes; const callbacks = { version: (_el) => { version = _decode_Version(_el); }, encryptedContentInfo: (_el) => { encryptedContentInfo = _decode_EncryptedContentInfo(_el); }, unprotectedAttributes: (_el) => { unprotectedAttributes = $._decode_implicit(() => _decode_Attributes)(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_EncryptedData, _extension_additions_list_spec_for_EncryptedData, _root_component_type_list_2_spec_for_EncryptedData, undefined); return new EncryptedData(version, encryptedContentInfo, unprotectedAttributes); }; } return _cached_decoder_for_EncryptedData(el); } let _cached_encoder_for_EncryptedData = null; /** * @summary Encodes a(n) EncryptedData 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 EncryptedData, encoded as an ASN.1 Element. */ export function _encode_EncryptedData(value, elGetter) { if (!_cached_encoder_for_EncryptedData) { _cached_encoder_for_EncryptedData = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_Version(value.version, $.BER), /* REQUIRED */ _encode_EncryptedContentInfo(value.encryptedContentInfo, $.BER), /* IF_ABSENT */ value.unprotectedAttributes === undefined ? undefined : $._encode_implicit(_TagClass.context, 1, () => _encode_Attributes, $.BER)(value.unprotectedAttributes, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_EncryptedData(value, elGetter); } /* eslint-enable */