@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
164 lines (163 loc) • 6.58 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_EncryptedKey, _encode_EncryptedKey, } from "../PKCS7/EncryptedKey.ta.mjs";
import { _decode_KeyEncryptionAlgorithmIdentifier, _encode_KeyEncryptionAlgorithmIdentifier, } from "../PKCS7/KeyEncryptionAlgorithmIdentifier.ta.mjs";
import { _decode_KeyEncryptionKeyIdentifier, _encode_KeyEncryptionKeyIdentifier, } from "../PKCS7/KeyEncryptionKeyIdentifier.ta.mjs";
import { _decode_Version, _encode_Version } from "../PKCS7/Version.ta.mjs";
/**
* @summary KeyEncryptionKeyRecipientInfo
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* KeyEncryptionKeyRecipientInfo ::= SEQUENCE {
* version Version,
* keyEncryptionKeyIdentifier KeyEncryptionKeyIdentifier,
* keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
* encryptedKey EncryptedKey
* }
* ```
*
*/
export class KeyEncryptionKeyRecipientInfo {
version;
keyEncryptionKeyIdentifier;
keyEncryptionAlgorithm;
encryptedKey;
constructor(
/**
* @summary `version`.
* @public
* @readonly
*/
version,
/**
* @summary `keyEncryptionKeyIdentifier`.
* @public
* @readonly
*/
keyEncryptionKeyIdentifier,
/**
* @summary `keyEncryptionAlgorithm`.
* @public
* @readonly
*/
keyEncryptionAlgorithm,
/**
* @summary `encryptedKey`.
* @public
* @readonly
*/
encryptedKey) {
this.version = version;
this.keyEncryptionKeyIdentifier = keyEncryptionKeyIdentifier;
this.keyEncryptionAlgorithm = keyEncryptionAlgorithm;
this.encryptedKey = encryptedKey;
}
/**
* @summary Restructures an object into a KeyEncryptionKeyRecipientInfo
* @description
*
* This takes an `object` and converts it to a `KeyEncryptionKeyRecipientInfo`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `KeyEncryptionKeyRecipientInfo`.
* @returns {KeyEncryptionKeyRecipientInfo}
*/
static _from_object(_o) {
return new KeyEncryptionKeyRecipientInfo(_o.version, _o.keyEncryptionKeyIdentifier, _o.keyEncryptionAlgorithm, _o.encryptedKey);
}
}
/**
* @summary The Leading Root Component Types of KeyEncryptionKeyRecipientInfo
* @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_KeyEncryptionKeyRecipientInfo = [
new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("keyEncryptionKeyIdentifier", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("keyEncryptionAlgorithm", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("encryptedKey", false, $.hasTag(_TagClass.universal, 4)),
];
/**
* @summary The Trailing Root Component Types of KeyEncryptionKeyRecipientInfo
* @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_KeyEncryptionKeyRecipientInfo = [];
/**
* @summary The Extension Addition Component Types of KeyEncryptionKeyRecipientInfo
* @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_KeyEncryptionKeyRecipientInfo = [];
let _cached_decoder_for_KeyEncryptionKeyRecipientInfo = null;
/**
* @summary Decodes an ASN.1 element into a(n) KeyEncryptionKeyRecipientInfo
* @function
* @param {_Element} el The element being decoded.
* @returns {KeyEncryptionKeyRecipientInfo} The decoded data structure.
*/
export function _decode_KeyEncryptionKeyRecipientInfo(el) {
if (!_cached_decoder_for_KeyEncryptionKeyRecipientInfo) {
_cached_decoder_for_KeyEncryptionKeyRecipientInfo = function (el) {
const sequence = el.sequence;
if (sequence.length < 4) {
throw new _ConstructionError("KeyEncryptionKeyRecipientInfo contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "version";
sequence[1].name = "keyEncryptionKeyIdentifier";
sequence[2].name = "keyEncryptionAlgorithm";
sequence[3].name = "encryptedKey";
let version;
let keyEncryptionKeyIdentifier;
let keyEncryptionAlgorithm;
let encryptedKey;
version = _decode_Version(sequence[0]);
keyEncryptionKeyIdentifier = _decode_KeyEncryptionKeyIdentifier(sequence[1]);
keyEncryptionAlgorithm = _decode_KeyEncryptionAlgorithmIdentifier(sequence[2]);
encryptedKey = _decode_EncryptedKey(sequence[3]);
return new KeyEncryptionKeyRecipientInfo(version, keyEncryptionKeyIdentifier, keyEncryptionAlgorithm, encryptedKey);
};
}
return _cached_decoder_for_KeyEncryptionKeyRecipientInfo(el);
}
let _cached_encoder_for_KeyEncryptionKeyRecipientInfo = null;
/**
* @summary Encodes a(n) KeyEncryptionKeyRecipientInfo 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 KeyEncryptionKeyRecipientInfo, encoded as an ASN.1 Element.
*/
export function _encode_KeyEncryptionKeyRecipientInfo(value, elGetter) {
if (!_cached_encoder_for_KeyEncryptionKeyRecipientInfo) {
_cached_encoder_for_KeyEncryptionKeyRecipientInfo = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_Version(value.version, $.BER),
/* REQUIRED */ _encode_KeyEncryptionKeyIdentifier(value.keyEncryptionKeyIdentifier, $.BER),
/* REQUIRED */ _encode_KeyEncryptionAlgorithmIdentifier(value.keyEncryptionAlgorithm, $.BER),
/* REQUIRED */ _encode_EncryptedKey(value.encryptedKey, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_KeyEncryptionKeyRecipientInfo(value, elGetter);
}
/* eslint-enable */