UNPKG

@wildboar/pkcs

Version:
183 lines (182 loc) 7.3 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_KeyEncryptionAlgorithmIdentifier, _encode_KeyEncryptionAlgorithmIdentifier, } from "../CryptographicMessageSyntax/KeyEncryptionAlgorithmIdentifier.ta.mjs"; import { _decode_OriginatorIdentifierOrKey, _encode_OriginatorIdentifierOrKey, } from "../CryptographicMessageSyntax/OriginatorIdentifierOrKey.ta.mjs"; import { _decode_RecipientEncryptedKeys, _encode_RecipientEncryptedKeys, } from "../CryptographicMessageSyntax/RecipientEncryptedKeys.ta.mjs"; import { _decode_UserKeyingMaterial, _encode_UserKeyingMaterial, } from "../CryptographicMessageSyntax/UserKeyingMaterial.ta.mjs"; /** * @summary KeyAgreeRecipientInfo * @description * * ### ASN.1 Definition: * * ```asn1 * KeyAgreeRecipientInfo ::= SEQUENCE { * version CMSVersion, -- always set to 3 * originator [0] EXPLICIT OriginatorIdentifierOrKey, * ukm [1] EXPLICIT UserKeyingMaterial OPTIONAL, * keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier, * recipientEncryptedKeys RecipientEncryptedKeys * } * ``` * */ export class KeyAgreeRecipientInfo { version; originator; ukm; keyEncryptionAlgorithm; recipientEncryptedKeys; constructor( /** * @summary `version`. * @public * @readonly */ version, /** * @summary `originator`. * @public * @readonly */ originator, /** * @summary `ukm`. * @public * @readonly */ ukm, /** * @summary `keyEncryptionAlgorithm`. * @public * @readonly */ keyEncryptionAlgorithm, /** * @summary `recipientEncryptedKeys`. * @public * @readonly */ recipientEncryptedKeys) { this.version = version; this.originator = originator; this.ukm = ukm; this.keyEncryptionAlgorithm = keyEncryptionAlgorithm; this.recipientEncryptedKeys = recipientEncryptedKeys; } /** * @summary Restructures an object into a KeyAgreeRecipientInfo * @description * * This takes an `object` and converts it to a `KeyAgreeRecipientInfo`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `KeyAgreeRecipientInfo`. * @returns {KeyAgreeRecipientInfo} */ static _from_object(_o) { return new KeyAgreeRecipientInfo(_o.version, _o.originator, _o.ukm, _o.keyEncryptionAlgorithm, _o.recipientEncryptedKeys); } } /** * @summary The Leading Root Component Types of KeyAgreeRecipientInfo * @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_KeyAgreeRecipientInfo = [ new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("originator", false, $.hasTag(_TagClass.context, 0)), new $.ComponentSpec("ukm", true, $.hasTag(_TagClass.context, 1)), new $.ComponentSpec("keyEncryptionAlgorithm", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("recipientEncryptedKeys", false, $.hasTag(_TagClass.universal, 16)), ]; /** * @summary The Trailing Root Component Types of KeyAgreeRecipientInfo * @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_KeyAgreeRecipientInfo = []; /** * @summary The Extension Addition Component Types of KeyAgreeRecipientInfo * @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_KeyAgreeRecipientInfo = []; let _cached_decoder_for_KeyAgreeRecipientInfo = null; /** * @summary Decodes an ASN.1 element into a(n) KeyAgreeRecipientInfo * @function * @param {_Element} el The element being decoded. * @returns {KeyAgreeRecipientInfo} The decoded data structure. */ export function _decode_KeyAgreeRecipientInfo(el) { if (!_cached_decoder_for_KeyAgreeRecipientInfo) { _cached_decoder_for_KeyAgreeRecipientInfo = function (el) { let version; let originator; let ukm; let keyEncryptionAlgorithm; let recipientEncryptedKeys; const callbacks = { version: (_el) => { version = _decode_CMSVersion(_el); }, originator: (_el) => { originator = $._decode_explicit(() => _decode_OriginatorIdentifierOrKey)(_el); }, ukm: (_el) => { ukm = $._decode_explicit(() => _decode_UserKeyingMaterial)(_el); }, keyEncryptionAlgorithm: (_el) => { keyEncryptionAlgorithm = _decode_KeyEncryptionAlgorithmIdentifier(_el); }, recipientEncryptedKeys: (_el) => { recipientEncryptedKeys = _decode_RecipientEncryptedKeys(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_KeyAgreeRecipientInfo, _extension_additions_list_spec_for_KeyAgreeRecipientInfo, _root_component_type_list_2_spec_for_KeyAgreeRecipientInfo, undefined); return new KeyAgreeRecipientInfo(version, originator, ukm, keyEncryptionAlgorithm, recipientEncryptedKeys); }; } return _cached_decoder_for_KeyAgreeRecipientInfo(el); } let _cached_encoder_for_KeyAgreeRecipientInfo = null; /** * @summary Encodes a(n) KeyAgreeRecipientInfo 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 KeyAgreeRecipientInfo, encoded as an ASN.1 Element. */ export function _encode_KeyAgreeRecipientInfo(value, elGetter) { if (!_cached_encoder_for_KeyAgreeRecipientInfo) { _cached_encoder_for_KeyAgreeRecipientInfo = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_CMSVersion(value.version, $.BER), /* REQUIRED */ $._encode_explicit(_TagClass.context, 0, () => _encode_OriginatorIdentifierOrKey, $.BER)(value.originator, $.BER), /* IF_ABSENT */ value.ukm === undefined ? undefined : $._encode_explicit(_TagClass.context, 1, () => _encode_UserKeyingMaterial, $.BER)(value.ukm, $.BER), /* REQUIRED */ _encode_KeyEncryptionAlgorithmIdentifier(value.keyEncryptionAlgorithm, $.BER), /* REQUIRED */ _encode_RecipientEncryptedKeys(value.recipientEncryptedKeys, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_KeyAgreeRecipientInfo(value, elGetter); } /* eslint-enable */