UNPKG

@wildboar/pkcs

Version:
133 lines (132 loc) 4.96 kB
/* eslint-disable */ import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_EncryptedData, _encode_EncryptedData, } from "../AsymmetricKeyPackageModuleV1/EncryptedData.ta.mjs"; import { _decode_EncryptionAlgorithmIdentifier, _encode_EncryptionAlgorithmIdentifier, } from "../AsymmetricKeyPackageModuleV1/EncryptionAlgorithmIdentifier.ta.mjs"; /** * @summary EncryptedPrivateKeyInfo * @description * * ### ASN.1 Definition: * * ```asn1 * EncryptedPrivateKeyInfo ::= SEQUENCE { * encryptionAlgorithm EncryptionAlgorithmIdentifier, * encryptedData EncryptedData } * ``` * */ export class EncryptedPrivateKeyInfo { encryptionAlgorithm; encryptedData; constructor( /** * @summary `encryptionAlgorithm`. * @public * @readonly */ encryptionAlgorithm, /** * @summary `encryptedData`. * @public * @readonly */ encryptedData) { this.encryptionAlgorithm = encryptionAlgorithm; this.encryptedData = encryptedData; } /** * @summary Restructures an object into a EncryptedPrivateKeyInfo * @description * * This takes an `object` and converts it to a `EncryptedPrivateKeyInfo`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `EncryptedPrivateKeyInfo`. * @returns {EncryptedPrivateKeyInfo} */ static _from_object(_o) { return new EncryptedPrivateKeyInfo(_o.encryptionAlgorithm, _o.encryptedData); } } /** * @summary The Leading Root Component Types of EncryptedPrivateKeyInfo * @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_EncryptedPrivateKeyInfo = [ new $.ComponentSpec("encryptionAlgorithm", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("encryptedData", false, $.hasTag(_TagClass.universal, 4)), ]; /** * @summary The Trailing Root Component Types of EncryptedPrivateKeyInfo * @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_EncryptedPrivateKeyInfo = []; /** * @summary The Extension Addition Component Types of EncryptedPrivateKeyInfo * @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_EncryptedPrivateKeyInfo = []; let _cached_decoder_for_EncryptedPrivateKeyInfo = null; /** * @summary Decodes an ASN.1 element into a(n) EncryptedPrivateKeyInfo * @function * @param {_Element} el The element being decoded. * @returns {EncryptedPrivateKeyInfo} The decoded data structure. */ export function _decode_EncryptedPrivateKeyInfo(el) { if (!_cached_decoder_for_EncryptedPrivateKeyInfo) { _cached_decoder_for_EncryptedPrivateKeyInfo = function (el) { const sequence = el.sequence; if (sequence.length < 2) { throw new _ConstructionError("EncryptedPrivateKeyInfo contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "encryptionAlgorithm"; sequence[1].name = "encryptedData"; let encryptionAlgorithm; let encryptedData; encryptionAlgorithm = _decode_EncryptionAlgorithmIdentifier(sequence[0]); encryptedData = _decode_EncryptedData(sequence[1]); return new EncryptedPrivateKeyInfo(encryptionAlgorithm, encryptedData); }; } return _cached_decoder_for_EncryptedPrivateKeyInfo(el); } let _cached_encoder_for_EncryptedPrivateKeyInfo = null; /** * @summary Encodes a(n) EncryptedPrivateKeyInfo 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 EncryptedPrivateKeyInfo, encoded as an ASN.1 Element. */ export function _encode_EncryptedPrivateKeyInfo(value, elGetter) { if (!_cached_encoder_for_EncryptedPrivateKeyInfo) { _cached_encoder_for_EncryptedPrivateKeyInfo = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_EncryptionAlgorithmIdentifier(value.encryptionAlgorithm, $.BER), /* REQUIRED */ _encode_EncryptedData(value.encryptedData, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_EncryptedPrivateKeyInfo(value, elGetter); } /* eslint-enable */