UNPKG

@wildboar/pkcs

Version:
162 lines 6.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._encode_Usage = exports._decode_Usage = exports._extension_additions_list_spec_for_Usage = exports._root_component_type_list_2_spec_for_Usage = exports._root_component_type_list_1_spec_for_Usage = exports.Usage = void 0; /* eslint-disable */ const asn1_ts_1 = require("asn1-ts"); const $ = require("asn1-ts/dist/node/functional"); const KeyUsage_ta_1 = require("@wildboar/x500/src/lib/modules/CertificateExtensions/KeyUsage.ta"); /* START_OF_SYMBOL_DEFINITION Usage */ /** * @summary Usage * @description * * ### ASN.1 Definition: * * ```asn1 * Usage ::= SEQUENCE { * keyUsage KeyUsage OPTIONAL, * extKeyUsage SEQUENCE SIZE (1..MAX) OF OBJECT IDENTIFIER OPTIONAL * }(WITH COMPONENTS {..., keyUsage PRESENT} | WITH COMPONENTS {..., extKeyUsage PRESENT}) * ``` * * @class */ class Usage { constructor( /** * @summary `keyUsage`. * @public * @readonly */ keyUsage, /** * @summary `extKeyUsage`. * @public * @readonly */ extKeyUsage) { this.keyUsage = keyUsage; this.extKeyUsage = extKeyUsage; } /** * @summary Restructures an object into a Usage * @description * * This takes an `object` and converts it to a `Usage`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `Usage`. * @returns {Usage} */ static _from_object(_o) { return new Usage(_o.keyUsage, _o.extKeyUsage); } } exports.Usage = Usage; /* END_OF_SYMBOL_DEFINITION Usage */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_Usage */ /** * @summary The Leading Root Component Types of Usage * @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 */ exports._root_component_type_list_1_spec_for_Usage = [ new $.ComponentSpec("keyUsage", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 3), undefined, undefined), new $.ComponentSpec("extKeyUsage", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined), ]; /* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_Usage */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_Usage */ /** * @summary The Trailing Root Component Types of Usage * @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 */ exports._root_component_type_list_2_spec_for_Usage = []; /* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_Usage */ /* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_Usage */ /** * @summary The Extension Addition Component Types of Usage * @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 */ exports._extension_additions_list_spec_for_Usage = []; /* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_Usage */ /* START_OF_SYMBOL_DEFINITION _cached_decoder_for_Usage */ let _cached_decoder_for_Usage = null; /* END_OF_SYMBOL_DEFINITION _cached_decoder_for_Usage */ /* START_OF_SYMBOL_DEFINITION _decode_Usage */ /** * @summary Decodes an ASN.1 element into a(n) Usage * @function * @param {_Element} el The element being decoded. * @returns {Usage} The decoded data structure. */ function _decode_Usage(el) { if (!_cached_decoder_for_Usage) { _cached_decoder_for_Usage = function (el) { /* START_OF_SEQUENCE_COMPONENT_DECLARATIONS */ let keyUsage; let extKeyUsage; /* END_OF_SEQUENCE_COMPONENT_DECLARATIONS */ /* START_OF_CALLBACKS_MAP */ const callbacks = { keyUsage: (_el) => { keyUsage = KeyUsage_ta_1._decode_KeyUsage(_el); }, extKeyUsage: (_el) => { extKeyUsage = $._decodeSequenceOf(() => $._decodeObjectIdentifier)(_el); }, }; /* END_OF_CALLBACKS_MAP */ $._parse_sequence(el, callbacks, exports._root_component_type_list_1_spec_for_Usage, exports._extension_additions_list_spec_for_Usage, exports._root_component_type_list_2_spec_for_Usage, undefined); return new Usage( /* SEQUENCE_CONSTRUCTOR_CALL */ keyUsage, extKeyUsage); }; } return _cached_decoder_for_Usage(el); } exports._decode_Usage = _decode_Usage; /* END_OF_SYMBOL_DEFINITION _decode_Usage */ /* START_OF_SYMBOL_DEFINITION _cached_encoder_for_Usage */ let _cached_encoder_for_Usage = null; /* END_OF_SYMBOL_DEFINITION _cached_encoder_for_Usage */ /* START_OF_SYMBOL_DEFINITION _encode_Usage */ /** * @summary Encodes a(n) Usage into an ASN.1 Element. * @function * @param {value} el The element being decoded. * @param elGetter A function that can be used to get new ASN.1 elements. * @returns {_Element} The Usage, encoded as an ASN.1 Element. */ function _encode_Usage(value, elGetter) { if (!_cached_encoder_for_Usage) { _cached_encoder_for_Usage = function (value, elGetter) { return $._encodeSequence([] .concat([ /* IF_ABSENT */ value.keyUsage === undefined ? undefined : KeyUsage_ta_1._encode_KeyUsage(value.keyUsage, $.BER), /* IF_ABSENT */ value.extKeyUsage === undefined ? undefined : $._encodeSequenceOf(() => $._encodeObjectIdentifier, $.BER)(value.extKeyUsage, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_Usage(value, elGetter); } exports._encode_Usage = _encode_Usage; /* END_OF_SYMBOL_DEFINITION _encode_Usage */ /* eslint-enable */ //# sourceMappingURL=Usage.ta.js.map