pkcs-ts
Version:
PKCS #1 through #15 (Except #11) - Private and Public Keys, Certificates, and More
129 lines • 7.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._encode_RSAPrivateKey = exports._decode_RSAPrivateKey = exports._extension_additions_list_spec_for_RSAPrivateKey = exports._root_component_type_list_2_spec_for_RSAPrivateKey = exports._root_component_type_list_1_spec_for_RSAPrivateKey = exports.RSAPrivateKey = exports._encode_Version = exports._decode_Version = exports.Version_two_prime = exports.Version_multi = exports.two_prime = exports.multi = exports._encode_OtherPrimeInfos = exports._decode_OtherPrimeInfos = void 0;
const tslib_1 = require("tslib");
const asn1_ts_1 = require("asn1-ts");
const $ = tslib_1.__importStar(require("asn1-ts/dist/node/functional"));
const OtherPrimeInfos_ta_1 = require("../PKCS-1/OtherPrimeInfos.ta");
const Version_ta_1 = require("../PKCS-1/Version.ta");
var OtherPrimeInfos_ta_2 = require("../PKCS-1/OtherPrimeInfos.ta");
Object.defineProperty(exports, "_decode_OtherPrimeInfos", { enumerable: true, get: function () { return OtherPrimeInfos_ta_2._decode_OtherPrimeInfos; } });
Object.defineProperty(exports, "_encode_OtherPrimeInfos", { enumerable: true, get: function () { return OtherPrimeInfos_ta_2._encode_OtherPrimeInfos; } });
var Version_ta_2 = require("../PKCS-1/Version.ta");
Object.defineProperty(exports, "multi", { enumerable: true, get: function () { return Version_ta_2.multi; } });
Object.defineProperty(exports, "two_prime", { enumerable: true, get: function () { return Version_ta_2.two_prime; } });
Object.defineProperty(exports, "Version_multi", { enumerable: true, get: function () { return Version_ta_2.Version_multi; } });
Object.defineProperty(exports, "Version_two_prime", { enumerable: true, get: function () { return Version_ta_2.Version_two_prime; } });
Object.defineProperty(exports, "_decode_Version", { enumerable: true, get: function () { return Version_ta_2._decode_Version; } });
Object.defineProperty(exports, "_encode_Version", { enumerable: true, get: function () { return Version_ta_2._encode_Version; } });
class RSAPrivateKey {
constructor(version, modulus, publicExponent, privateExponent, prime1, prime2, exponent1, exponent2, coefficient, otherPrimeInfos) {
this.version = version;
this.modulus = modulus;
this.publicExponent = publicExponent;
this.privateExponent = privateExponent;
this.prime1 = prime1;
this.prime2 = prime2;
this.exponent1 = exponent1;
this.exponent2 = exponent2;
this.coefficient = coefficient;
this.otherPrimeInfos = otherPrimeInfos;
}
static _from_object(_o) {
return new RSAPrivateKey(_o.version, _o.modulus, _o.publicExponent, _o.privateExponent, _o.prime1, _o.prime2, _o.exponent1, _o.exponent2, _o.coefficient, _o.otherPrimeInfos);
}
}
exports.RSAPrivateKey = RSAPrivateKey;
exports._root_component_type_list_1_spec_for_RSAPrivateKey = [
new $.ComponentSpec("version", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
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),
new $.ComponentSpec("privateExponent", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
new $.ComponentSpec("prime1", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
new $.ComponentSpec("prime2", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
new $.ComponentSpec("exponent1", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
new $.ComponentSpec("exponent2", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
new $.ComponentSpec("coefficient", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
new $.ComponentSpec("otherPrimeInfos", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined),
];
exports._root_component_type_list_2_spec_for_RSAPrivateKey = [];
exports._extension_additions_list_spec_for_RSAPrivateKey = [];
let _cached_decoder_for_RSAPrivateKey = null;
function _decode_RSAPrivateKey(el) {
if (!_cached_decoder_for_RSAPrivateKey) {
_cached_decoder_for_RSAPrivateKey = function (el) {
let version;
let modulus;
let publicExponent;
let privateExponent;
let prime1;
let prime2;
let exponent1;
let exponent2;
let coefficient;
let otherPrimeInfos;
const callbacks = {
version: (_el) => {
version = Version_ta_1._decode_Version(_el);
},
modulus: (_el) => {
modulus = $._decodeBigInt(_el);
},
publicExponent: (_el) => {
publicExponent = $._decodeBigInt(_el);
},
privateExponent: (_el) => {
privateExponent = $._decodeBigInt(_el);
},
prime1: (_el) => {
prime1 = $._decodeBigInt(_el);
},
prime2: (_el) => {
prime2 = $._decodeBigInt(_el);
},
exponent1: (_el) => {
exponent1 = $._decodeBigInt(_el);
},
exponent2: (_el) => {
exponent2 = $._decodeBigInt(_el);
},
coefficient: (_el) => {
coefficient = $._decodeBigInt(_el);
},
otherPrimeInfos: (_el) => {
otherPrimeInfos = OtherPrimeInfos_ta_1._decode_OtherPrimeInfos(_el);
},
};
$._parse_sequence(el, callbacks, exports._root_component_type_list_1_spec_for_RSAPrivateKey, exports._extension_additions_list_spec_for_RSAPrivateKey, exports._root_component_type_list_2_spec_for_RSAPrivateKey, undefined);
return new RSAPrivateKey(version, modulus, publicExponent, privateExponent, prime1, prime2, exponent1, exponent2, coefficient, otherPrimeInfos);
};
}
return _cached_decoder_for_RSAPrivateKey(el);
}
exports._decode_RSAPrivateKey = _decode_RSAPrivateKey;
let _cached_encoder_for_RSAPrivateKey = null;
function _encode_RSAPrivateKey(value, elGetter) {
if (!_cached_encoder_for_RSAPrivateKey) {
_cached_encoder_for_RSAPrivateKey = function (value, elGetter) {
return $._encodeSequence([]
.concat([
Version_ta_1._encode_Version(value.version, $.BER),
$._encodeBigInt(value.modulus, $.BER),
$._encodeBigInt(value.publicExponent, $.BER),
$._encodeBigInt(value.privateExponent, $.BER),
$._encodeBigInt(value.prime1, $.BER),
$._encodeBigInt(value.prime2, $.BER),
$._encodeBigInt(value.exponent1, $.BER),
$._encodeBigInt(value.exponent2, $.BER),
$._encodeBigInt(value.coefficient, $.BER),
value.otherPrimeInfos === undefined
? undefined
: OtherPrimeInfos_ta_1._encode_OtherPrimeInfos(value.otherPrimeInfos, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_RSAPrivateKey(value, elGetter);
}
exports._encode_RSAPrivateKey = _encode_RSAPrivateKey;
//# sourceMappingURL=RSAPrivateKey.ta.js.map