UNPKG

@wildboar/pkcs

Version:
151 lines (150 loc) 5.89 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_ContentEncryptionAlgorithmIdentifier, _encode_ContentEncryptionAlgorithmIdentifier, } from "../CryptographicMessageSyntax/ContentEncryptionAlgorithmIdentifier.ta.mjs"; import { _decode_ContentType, _encode_ContentType, } from "../CryptographicMessageSyntax/ContentType.ta.mjs"; import { _decode_EncryptedContent, _encode_EncryptedContent, } from "../CryptographicMessageSyntax/EncryptedContent.ta.mjs"; /** * @summary EncryptedContentInfo * @description * * ### ASN.1 Definition: * * ```asn1 * EncryptedContentInfo ::= SEQUENCE { * contentType ContentType, * contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier, * encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL * } * ``` * */ export class EncryptedContentInfo { contentType; contentEncryptionAlgorithm; encryptedContent; constructor( /** * @summary `contentType`. * @public * @readonly */ contentType, /** * @summary `contentEncryptionAlgorithm`. * @public * @readonly */ contentEncryptionAlgorithm, /** * @summary `encryptedContent`. * @public * @readonly */ encryptedContent) { this.contentType = contentType; this.contentEncryptionAlgorithm = contentEncryptionAlgorithm; this.encryptedContent = encryptedContent; } /** * @summary Restructures an object into a EncryptedContentInfo * @description * * This takes an `object` and converts it to a `EncryptedContentInfo`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `EncryptedContentInfo`. * @returns {EncryptedContentInfo} */ static _from_object(_o) { return new EncryptedContentInfo(_o.contentType, _o.contentEncryptionAlgorithm, _o.encryptedContent); } } /** * @summary The Leading Root Component Types of EncryptedContentInfo * @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_EncryptedContentInfo = [ new $.ComponentSpec("contentType", false, $.hasTag(_TagClass.universal, 6)), new $.ComponentSpec("contentEncryptionAlgorithm", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("encryptedContent", true, $.hasTag(_TagClass.context, 0)), ]; /** * @summary The Trailing Root Component Types of EncryptedContentInfo * @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_EncryptedContentInfo = []; /** * @summary The Extension Addition Component Types of EncryptedContentInfo * @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_EncryptedContentInfo = []; let _cached_decoder_for_EncryptedContentInfo = null; /** * @summary Decodes an ASN.1 element into a(n) EncryptedContentInfo * @function * @param {_Element} el The element being decoded. * @returns {EncryptedContentInfo} The decoded data structure. */ export function _decode_EncryptedContentInfo(el) { if (!_cached_decoder_for_EncryptedContentInfo) { _cached_decoder_for_EncryptedContentInfo = function (el) { let contentType; let contentEncryptionAlgorithm; let encryptedContent; const callbacks = { contentType: (_el) => { contentType = _decode_ContentType(_el); }, contentEncryptionAlgorithm: (_el) => { contentEncryptionAlgorithm = _decode_ContentEncryptionAlgorithmIdentifier(_el); }, encryptedContent: (_el) => { encryptedContent = $._decode_implicit(() => _decode_EncryptedContent)(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_EncryptedContentInfo, _extension_additions_list_spec_for_EncryptedContentInfo, _root_component_type_list_2_spec_for_EncryptedContentInfo, undefined); return new EncryptedContentInfo(contentType, contentEncryptionAlgorithm, encryptedContent); }; } return _cached_decoder_for_EncryptedContentInfo(el); } let _cached_encoder_for_EncryptedContentInfo = null; /** * @summary Encodes a(n) EncryptedContentInfo 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 EncryptedContentInfo, encoded as an ASN.1 Element. */ export function _encode_EncryptedContentInfo(value, elGetter) { if (!_cached_encoder_for_EncryptedContentInfo) { _cached_encoder_for_EncryptedContentInfo = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_ContentType(value.contentType, $.BER), /* REQUIRED */ _encode_ContentEncryptionAlgorithmIdentifier(value.contentEncryptionAlgorithm, $.BER), /* IF_ABSENT */ value.encryptedContent === undefined ? undefined : $._encode_implicit(_TagClass.context, 0, () => _encode_EncryptedContent, $.BER)(value.encryptedContent, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_EncryptedContentInfo(value, elGetter); } /* eslint-enable */