UNPKG

@wildboar/pkcs

Version:
141 lines (140 loc) 5.12 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "@wildboar/x500/AuthenticationFramework"; /** * @summary EncryptedContentInfo * @description * * ### ASN.1 Definition: * * ```asn1 * EncryptedContentInfo {Type} ::= SEQUENCE { * contentType OBJECT IDENTIFIER, * contentEncryptionAlgorithm AlgorithmIdentifier{{ContentEncryptionAlgorithms}}, * encryptedContent [0] OCTET STRING OPTIONAL * }(CONSTRAINED BY { * -- 'encryptedContent' shall be the result of encrypting DER-encoded * -- value of type -- Type}) * ``` * */ 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 = []; /** * @summary Returns a function that will decode an ASN.1 element into a(n) EncryptedContentInfo * @function * @param {_Element} el The element being decoded. * @returns A function that will decode an ASN.1 element. */ export function _get_decoder_for_EncryptedContentInfo(_decode_Type) { return function (el) { let contentType; let contentEncryptionAlgorithm; let encryptedContent; const callbacks = { contentType: (_el) => { contentType = $._decodeObjectIdentifier(_el); }, contentEncryptionAlgorithm: (_el) => { contentEncryptionAlgorithm = _decode_AlgorithmIdentifier(_el); }, encryptedContent: (_el) => { encryptedContent = $._decode_implicit(() => $._decodeOctetString)(_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); }; } /** * @summary Returns a function that will encode a(n) EncryptedContentInfo into an ASN.1 Element. * @function * @returns A function that will encode a(n) EncryptedContentInfo as an ASN.1 element. */ export function _get_encoder_for_EncryptedContentInfo(_encode_Type) { return function (value, _elGetter) { return $._encodeSequence([] .concat([ /* REQUIRED */ $._encodeObjectIdentifier(value.contentType, $.BER), /* REQUIRED */ _encode_AlgorithmIdentifier(value.contentEncryptionAlgorithm, $.BER), /* IF_ABSENT */ value.encryptedContent === undefined ? undefined : $._encode_implicit(_TagClass.context, 0, () => $._encodeOctetString, $.BER)(value.encryptedContent, $.BER), ]) .filter((c) => !!c), $.BER); }; } /* eslint-enable */