UNPKG

@wildboar/pki-stub

Version:
147 lines 5.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._encode_SubjectPublicKeyInfo = exports._decode_SubjectPublicKeyInfo = exports._extension_additions_list_spec_for_SubjectPublicKeyInfo = exports._root_component_type_list_2_spec_for_SubjectPublicKeyInfo = exports._root_component_type_list_1_spec_for_SubjectPublicKeyInfo = exports.SubjectPublicKeyInfo = void 0; /* eslint-disable */ const asn1_ts_1 = require("asn1-ts"); const $ = require("asn1-ts/dist/node/functional"); const AlgorithmIdentifier_ta_1 = require("../PKI-Stub/AlgorithmIdentifier.ta"); const PublicKey_ta_1 = require("../PKI-Stub/PublicKey.ta"); /* START_OF_SYMBOL_DEFINITION SubjectPublicKeyInfo */ /** * @summary SubjectPublicKeyInfo * @description * * ### ASN.1 Definition: * * ```asn1 * SubjectPublicKeyInfo ::= SEQUENCE { * algorithm AlgorithmIdentifier{{SupportedAlgorithms}}, * subjectPublicKey PublicKey, * ... } * ``` * * @class */ class SubjectPublicKeyInfo { constructor( /** * @summary `algorithm`. * @public * @readonly */ algorithm, /** * @summary `subjectPublicKey`. * @public * @readonly */ subjectPublicKey, /** * @summary Extensions that are not recognized. * @public * @readonly */ _unrecognizedExtensionsList = []) { this.algorithm = algorithm; this.subjectPublicKey = subjectPublicKey; this._unrecognizedExtensionsList = _unrecognizedExtensionsList; } /** * @summary Restructures an object into a SubjectPublicKeyInfo * @description * * This takes an `object` and converts it to a `SubjectPublicKeyInfo`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `SubjectPublicKeyInfo`. * @returns {SubjectPublicKeyInfo} */ static _from_object(_o) { return new SubjectPublicKeyInfo(_o.algorithm, _o.subjectPublicKey, _o._unrecognizedExtensionsList); } } exports.SubjectPublicKeyInfo = SubjectPublicKeyInfo; /* END_OF_SYMBOL_DEFINITION SubjectPublicKeyInfo */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_SubjectPublicKeyInfo */ /** * @summary The Leading Root Component Types of SubjectPublicKeyInfo * @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_SubjectPublicKeyInfo = [ new $.ComponentSpec("algorithm", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined), new $.ComponentSpec("subjectPublicKey", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 3), undefined, undefined), ]; /* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_SubjectPublicKeyInfo */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_SubjectPublicKeyInfo */ /** * @summary The Trailing Root Component Types of SubjectPublicKeyInfo * @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_SubjectPublicKeyInfo = []; /* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_SubjectPublicKeyInfo */ /* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_SubjectPublicKeyInfo */ /** * @summary The Extension Addition Component Types of SubjectPublicKeyInfo * @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_SubjectPublicKeyInfo = []; /* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_SubjectPublicKeyInfo */ /* START_OF_SYMBOL_DEFINITION _decode_SubjectPublicKeyInfo */ /** * @summary Decodes an ASN.1 element into a(n) SubjectPublicKeyInfo * @function * @param {_Element} el The element being decoded. * @returns {SubjectPublicKeyInfo} The decoded data structure. */ function _decode_SubjectPublicKeyInfo(el) { const sequence = el.sequence; if (sequence.length < 2) { throw new asn1_ts_1.ASN1ConstructionError("SubjectPublicKeyInfo contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "algorithm"; sequence[1].name = "subjectPublicKey"; let algorithm; let subjectPublicKey; algorithm = AlgorithmIdentifier_ta_1._decode_AlgorithmIdentifier(sequence[0]); subjectPublicKey = PublicKey_ta_1._decode_PublicKey(sequence[1]); return new SubjectPublicKeyInfo(algorithm, subjectPublicKey, sequence.slice(2)); } exports._decode_SubjectPublicKeyInfo = _decode_SubjectPublicKeyInfo; /* END_OF_SYMBOL_DEFINITION _decode_SubjectPublicKeyInfo */ /* START_OF_SYMBOL_DEFINITION _encode_SubjectPublicKeyInfo */ /** * @summary Encodes a(n) SubjectPublicKeyInfo 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 SubjectPublicKeyInfo, encoded as an ASN.1 Element. */ function _encode_SubjectPublicKeyInfo(value, elGetter) { var _a; const components = [ /* REQUIRED */ AlgorithmIdentifier_ta_1._encode_AlgorithmIdentifier(value.algorithm, $.BER), /* REQUIRED */ PublicKey_ta_1._encode_PublicKey(value.subjectPublicKey, $.BER), ...(_a = value._unrecognizedExtensionsList) !== null && _a !== void 0 ? _a : [], ]; return $._encodeSequence(components, $.BER); } exports._encode_SubjectPublicKeyInfo = _encode_SubjectPublicKeyInfo; /* END_OF_SYMBOL_DEFINITION _encode_SubjectPublicKeyInfo */ /* eslint-enable */ //# sourceMappingURL=SubjectPublicKeyInfo.ta.js.map