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