@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
152 lines (151 loc) • 5.45 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_OtherKeyAttribute, _encode_OtherKeyAttribute, } from "../CryptographicMessageSyntax/OtherKeyAttribute.ta.mjs";
import { _decode_SubjectKeyIdentifier, _encode_SubjectKeyIdentifier, } from "../CryptographicMessageSyntax/SubjectKeyIdentifier.ta.mjs";
/**
* @summary RecipientKeyIdentifier
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* RecipientKeyIdentifier ::= SEQUENCE {
* subjectKeyIdentifier SubjectKeyIdentifier,
* date GeneralizedTime OPTIONAL,
* other OtherKeyAttribute OPTIONAL
* }
* ```
*
*/
export class RecipientKeyIdentifier {
subjectKeyIdentifier;
date;
other;
constructor(
/**
* @summary `subjectKeyIdentifier`.
* @public
* @readonly
*/
subjectKeyIdentifier,
/**
* @summary `date`.
* @public
* @readonly
*/
date,
/**
* @summary `other`.
* @public
* @readonly
*/
other) {
this.subjectKeyIdentifier = subjectKeyIdentifier;
this.date = date;
this.other = other;
}
/**
* @summary Restructures an object into a RecipientKeyIdentifier
* @description
*
* This takes an `object` and converts it to a `RecipientKeyIdentifier`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `RecipientKeyIdentifier`.
* @returns {RecipientKeyIdentifier}
*/
static _from_object(_o) {
return new RecipientKeyIdentifier(_o.subjectKeyIdentifier, _o.date, _o.other);
}
}
/**
* @summary The Leading Root Component Types of RecipientKeyIdentifier
* @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_RecipientKeyIdentifier = [
new $.ComponentSpec("subjectKeyIdentifier", false, $.hasTag(_TagClass.universal, 4)),
new $.ComponentSpec("date", true, $.hasTag(_TagClass.universal, 24)),
new $.ComponentSpec("other", true, $.hasTag(_TagClass.universal, 16)),
];
/**
* @summary The Trailing Root Component Types of RecipientKeyIdentifier
* @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_RecipientKeyIdentifier = [];
/**
* @summary The Extension Addition Component Types of RecipientKeyIdentifier
* @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_RecipientKeyIdentifier = [];
let _cached_decoder_for_RecipientKeyIdentifier = null;
/**
* @summary Decodes an ASN.1 element into a(n) RecipientKeyIdentifier
* @function
* @param {_Element} el The element being decoded.
* @returns {RecipientKeyIdentifier} The decoded data structure.
*/
export function _decode_RecipientKeyIdentifier(el) {
if (!_cached_decoder_for_RecipientKeyIdentifier) {
_cached_decoder_for_RecipientKeyIdentifier = function (el) {
let subjectKeyIdentifier;
let date;
let other;
const callbacks = {
subjectKeyIdentifier: (_el) => {
subjectKeyIdentifier = _decode_SubjectKeyIdentifier(_el);
},
date: (_el) => {
date = $._decodeGeneralizedTime(_el);
},
other: (_el) => {
other = _decode_OtherKeyAttribute(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_RecipientKeyIdentifier, _extension_additions_list_spec_for_RecipientKeyIdentifier, _root_component_type_list_2_spec_for_RecipientKeyIdentifier, undefined);
return new RecipientKeyIdentifier(subjectKeyIdentifier, date, other);
};
}
return _cached_decoder_for_RecipientKeyIdentifier(el);
}
let _cached_encoder_for_RecipientKeyIdentifier = null;
/**
* @summary Encodes a(n) RecipientKeyIdentifier 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 RecipientKeyIdentifier, encoded as an ASN.1 Element.
*/
export function _encode_RecipientKeyIdentifier(value, elGetter) {
if (!_cached_encoder_for_RecipientKeyIdentifier) {
_cached_encoder_for_RecipientKeyIdentifier = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_SubjectKeyIdentifier(value.subjectKeyIdentifier, $.BER),
/* IF_ABSENT */ value.date === undefined
? undefined
: $._encodeGeneralizedTime(value.date, $.BER),
/* IF_ABSENT */ value.other === undefined
? undefined
: _encode_OtherKeyAttribute(value.other, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_RecipientKeyIdentifier(value, elGetter);
}
/* eslint-enable */