UNPKG

@wildboar/pkcs

Version:
153 lines 5.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._encode_RSAPublicKey = exports._decode_RSAPublicKey = exports._extension_additions_list_spec_for_RSAPublicKey = exports._root_component_type_list_2_spec_for_RSAPublicKey = exports._root_component_type_list_1_spec_for_RSAPublicKey = exports.RSAPublicKey = void 0; /* eslint-disable */ const asn1_ts_1 = require("asn1-ts"); const $ = require("asn1-ts/dist/node/functional"); /* START_OF_SYMBOL_DEFINITION RSAPublicKey */ /** * @summary RSAPublicKey * @description * * ### ASN.1 Definition: * * ```asn1 * RSAPublicKey ::= SEQUENCE { * modulus INTEGER, -- n * publicExponent INTEGER -- e * } * ``` * * @class */ class RSAPublicKey { constructor( /** * @summary `modulus`. * @public * @readonly */ modulus, /** * @summary `publicExponent`. * @public * @readonly */ publicExponent) { this.modulus = modulus; this.publicExponent = publicExponent; } /** * @summary Restructures an object into a RSAPublicKey * @description * * This takes an `object` and converts it to a `RSAPublicKey`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `RSAPublicKey`. * @returns {RSAPublicKey} */ static _from_object(_o) { return new RSAPublicKey(_o.modulus, _o.publicExponent); } } exports.RSAPublicKey = RSAPublicKey; /* END_OF_SYMBOL_DEFINITION RSAPublicKey */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_RSAPublicKey */ /** * @summary The Leading Root Component Types of RSAPublicKey * @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_RSAPublicKey = [ new $.ComponentSpec("modulus", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined), new $.ComponentSpec("publicExponent", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined), ]; /* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_RSAPublicKey */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_RSAPublicKey */ /** * @summary The Trailing Root Component Types of RSAPublicKey * @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_RSAPublicKey = []; /* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_RSAPublicKey */ /* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_RSAPublicKey */ /** * @summary The Extension Addition Component Types of RSAPublicKey * @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_RSAPublicKey = []; /* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_RSAPublicKey */ /* START_OF_SYMBOL_DEFINITION _cached_decoder_for_RSAPublicKey */ let _cached_decoder_for_RSAPublicKey = null; /* END_OF_SYMBOL_DEFINITION _cached_decoder_for_RSAPublicKey */ /* START_OF_SYMBOL_DEFINITION _decode_RSAPublicKey */ /** * @summary Decodes an ASN.1 element into a(n) RSAPublicKey * @function * @param {_Element} el The element being decoded. * @returns {RSAPublicKey} The decoded data structure. */ function _decode_RSAPublicKey(el) { if (!_cached_decoder_for_RSAPublicKey) { _cached_decoder_for_RSAPublicKey = function (el) { const sequence = el.sequence; if (sequence.length < 2) { throw new asn1_ts_1.ASN1ConstructionError("RSAPublicKey contained only " + sequence.length.toString() + " elements."); } sequence[0].name = "modulus"; sequence[1].name = "publicExponent"; let modulus; let publicExponent; modulus = $._decodeInteger(sequence[0]); publicExponent = $._decodeInteger(sequence[1]); return new RSAPublicKey(modulus, publicExponent); }; } return _cached_decoder_for_RSAPublicKey(el); } exports._decode_RSAPublicKey = _decode_RSAPublicKey; /* END_OF_SYMBOL_DEFINITION _decode_RSAPublicKey */ /* START_OF_SYMBOL_DEFINITION _cached_encoder_for_RSAPublicKey */ let _cached_encoder_for_RSAPublicKey = null; /* END_OF_SYMBOL_DEFINITION _cached_encoder_for_RSAPublicKey */ /* START_OF_SYMBOL_DEFINITION _encode_RSAPublicKey */ /** * @summary Encodes a(n) RSAPublicKey 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 RSAPublicKey, encoded as an ASN.1 Element. */ function _encode_RSAPublicKey(value, elGetter) { if (!_cached_encoder_for_RSAPublicKey) { _cached_encoder_for_RSAPublicKey = function (value, elGetter) { return $._encodeSequence([] .concat([ /* REQUIRED */ $._encodeInteger(value.modulus, $.BER), /* REQUIRED */ $._encodeInteger(value.publicExponent, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_RSAPublicKey(value, elGetter); } exports._encode_RSAPublicKey = _encode_RSAPublicKey; /* END_OF_SYMBOL_DEFINITION _encode_RSAPublicKey */ /* eslint-enable */ //# sourceMappingURL=RSAPublicKey.ta.js.map