UNPKG

pkcs-ts

Version:

PKCS #1 through #15 (Except #11) - Private and Public Keys, Certificates, and More

60 lines 2.79 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; const tslib_1 = require("tslib"); const asn1_ts_1 = require("asn1-ts"); const $ = tslib_1.__importStar(require("asn1-ts/dist/node/functional")); class RSAPublicKey { constructor(modulus, publicExponent) { this.modulus = modulus; this.publicExponent = publicExponent; } static _from_object(_o) { return new RSAPublicKey(_o.modulus, _o.publicExponent); } } exports.RSAPublicKey = RSAPublicKey; 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), ]; exports._root_component_type_list_2_spec_for_RSAPublicKey = []; exports._extension_additions_list_spec_for_RSAPublicKey = []; let _cached_decoder_for_RSAPublicKey = null; 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; let _cached_encoder_for_RSAPublicKey = null; function _encode_RSAPublicKey(value, elGetter) { if (!_cached_encoder_for_RSAPublicKey) { _cached_encoder_for_RSAPublicKey = function (value, elGetter) { return $._encodeSequence([] .concat([ $._encodeInteger(value.modulus, $.BER), $._encodeInteger(value.publicExponent, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_RSAPublicKey(value, elGetter); } exports._encode_RSAPublicKey = _encode_RSAPublicKey; //# sourceMappingURL=RSAPublicKey.ta.js.map