UNPKG

@wildboar/pkcs

Version:
151 lines (150 loc) 4.9 kB
/* 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"; /** * @summary KEKIdentifier * @description * * ### ASN.1 Definition: * * ```asn1 * KEKIdentifier ::= SEQUENCE { * keyIdentifier OCTET STRING, * date GeneralizedTime OPTIONAL, * other OtherKeyAttribute OPTIONAL * } * ``` * */ export class KEKIdentifier { keyIdentifier; date; other; constructor( /** * @summary `keyIdentifier`. * @public * @readonly */ keyIdentifier, /** * @summary `date`. * @public * @readonly */ date, /** * @summary `other`. * @public * @readonly */ other) { this.keyIdentifier = keyIdentifier; this.date = date; this.other = other; } /** * @summary Restructures an object into a KEKIdentifier * @description * * This takes an `object` and converts it to a `KEKIdentifier`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `KEKIdentifier`. * @returns {KEKIdentifier} */ static _from_object(_o) { return new KEKIdentifier(_o.keyIdentifier, _o.date, _o.other); } } /** * @summary The Leading Root Component Types of KEKIdentifier * @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_KEKIdentifier = [ new $.ComponentSpec("keyIdentifier", 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 KEKIdentifier * @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_KEKIdentifier = []; /** * @summary The Extension Addition Component Types of KEKIdentifier * @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_KEKIdentifier = []; let _cached_decoder_for_KEKIdentifier = null; /** * @summary Decodes an ASN.1 element into a(n) KEKIdentifier * @function * @param {_Element} el The element being decoded. * @returns {KEKIdentifier} The decoded data structure. */ export function _decode_KEKIdentifier(el) { if (!_cached_decoder_for_KEKIdentifier) { _cached_decoder_for_KEKIdentifier = function (el) { let keyIdentifier; let date; let other; const callbacks = { keyIdentifier: (_el) => { keyIdentifier = $._decodeOctetString(_el); }, date: (_el) => { date = $._decodeGeneralizedTime(_el); }, other: (_el) => { other = _decode_OtherKeyAttribute(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_KEKIdentifier, _extension_additions_list_spec_for_KEKIdentifier, _root_component_type_list_2_spec_for_KEKIdentifier, undefined); return new KEKIdentifier(keyIdentifier, date, other); }; } return _cached_decoder_for_KEKIdentifier(el); } let _cached_encoder_for_KEKIdentifier = null; /** * @summary Encodes a(n) KEKIdentifier 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 KEKIdentifier, encoded as an ASN.1 Element. */ export function _encode_KEKIdentifier(value, elGetter) { if (!_cached_encoder_for_KEKIdentifier) { _cached_encoder_for_KEKIdentifier = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ $._encodeOctetString(value.keyIdentifier, $.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_KEKIdentifier(value, elGetter); } /* eslint-enable */