@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
283 lines • 12.1 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;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = 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; } }); /* IMPORTED_SHORT_NAMED_INTEGER */
Object.defineProperty(exports, "two_prime", { enumerable: true, get: function () { return Version_ta_2.two_prime; } }); /* IMPORTED_SHORT_NAMED_INTEGER */
Object.defineProperty(exports, "Version_multi", { enumerable: true, get: function () { return Version_ta_2.Version_multi; } }); /* IMPORTED_LONG_NAMED_INTEGER */
Object.defineProperty(exports, "Version_two_prime", { enumerable: true, get: function () { return Version_ta_2.Version_two_prime; } }); /* IMPORTED_LONG_NAMED_INTEGER */
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; } });
/* START_OF_SYMBOL_DEFINITION RSAPrivateKey */
/**
* @summary RSAPrivateKey
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* RSAPrivateKey ::= SEQUENCE {
* version Version,
* modulus INTEGER, -- n
* publicExponent INTEGER, -- e
* privateExponent INTEGER, -- d
* prime1 INTEGER, -- p
* prime2 INTEGER, -- q
* exponent1 INTEGER, -- d mod (p-1)
* exponent2 INTEGER, -- d mod (q-1)
* coefficient INTEGER, -- (inverse of q) mod p
* otherPrimeInfos OtherPrimeInfos OPTIONAL
* }
* ```
*
* @class
*/
class RSAPrivateKey {
constructor(
/**
* @summary `version`.
* @public
* @readonly
*/
version,
/**
* @summary `modulus`.
* @public
* @readonly
*/
modulus,
/**
* @summary `publicExponent`.
* @public
* @readonly
*/
publicExponent,
/**
* @summary `privateExponent`.
* @public
* @readonly
*/
privateExponent,
/**
* @summary `prime1`.
* @public
* @readonly
*/
prime1,
/**
* @summary `prime2`.
* @public
* @readonly
*/
prime2,
/**
* @summary `exponent1`.
* @public
* @readonly
*/
exponent1,
/**
* @summary `exponent2`.
* @public
* @readonly
*/
exponent2,
/**
* @summary `coefficient`.
* @public
* @readonly
*/
coefficient,
/**
* @summary `otherPrimeInfos`.
* @public
* @readonly
*/
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;
}
/**
* @summary Restructures an object into a RSAPrivateKey
* @description
*
* This takes an `object` and converts it to a `RSAPrivateKey`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `RSAPrivateKey`.
* @returns {RSAPrivateKey}
*/
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;
/* END_OF_SYMBOL_DEFINITION RSAPrivateKey */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_RSAPrivateKey */
/**
* @summary The Leading Root Component Types of RSAPrivateKey
* @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_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),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_RSAPrivateKey */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_RSAPrivateKey */
/**
* @summary The Trailing Root Component Types of RSAPrivateKey
* @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_RSAPrivateKey = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_RSAPrivateKey */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_RSAPrivateKey */
/**
* @summary The Extension Addition Component Types of RSAPrivateKey
* @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_RSAPrivateKey = [];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_RSAPrivateKey */
/* START_OF_SYMBOL_DEFINITION _cached_decoder_for_RSAPrivateKey */
let _cached_decoder_for_RSAPrivateKey = null;
/* END_OF_SYMBOL_DEFINITION _cached_decoder_for_RSAPrivateKey */
/* START_OF_SYMBOL_DEFINITION _decode_RSAPrivateKey */
/**
* @summary Decodes an ASN.1 element into a(n) RSAPrivateKey
* @function
* @param {_Element} el The element being decoded.
* @returns {RSAPrivateKey} The decoded data structure.
*/
function _decode_RSAPrivateKey(el) {
if (!_cached_decoder_for_RSAPrivateKey) {
_cached_decoder_for_RSAPrivateKey = function (el) {
/* START_OF_SEQUENCE_COMPONENT_DECLARATIONS */
let version;
let modulus;
let publicExponent;
let privateExponent;
let prime1;
let prime2;
let exponent1;
let exponent2;
let coefficient;
let otherPrimeInfos;
/* END_OF_SEQUENCE_COMPONENT_DECLARATIONS */
/* START_OF_CALLBACKS_MAP */
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);
},
};
/* END_OF_CALLBACKS_MAP */
$._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(
/* SEQUENCE_CONSTRUCTOR_CALL */ version, modulus, publicExponent, privateExponent, prime1, prime2, exponent1, exponent2, coefficient, otherPrimeInfos);
};
}
return _cached_decoder_for_RSAPrivateKey(el);
}
exports._decode_RSAPrivateKey = _decode_RSAPrivateKey;
/* END_OF_SYMBOL_DEFINITION _decode_RSAPrivateKey */
/* START_OF_SYMBOL_DEFINITION _cached_encoder_for_RSAPrivateKey */
let _cached_encoder_for_RSAPrivateKey = null;
/* END_OF_SYMBOL_DEFINITION _cached_encoder_for_RSAPrivateKey */
/* START_OF_SYMBOL_DEFINITION _encode_RSAPrivateKey */
/**
* @summary Encodes a(n) RSAPrivateKey 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 RSAPrivateKey, encoded as an ASN.1 Element.
*/
function _encode_RSAPrivateKey(value, elGetter) {
if (!_cached_encoder_for_RSAPrivateKey) {
_cached_encoder_for_RSAPrivateKey = function (value, elGetter) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ Version_ta_1._encode_Version(value.version, $.BER),
/* REQUIRED */ $._encodeBigInt(value.modulus, $.BER),
/* REQUIRED */ $._encodeBigInt(value.publicExponent, $.BER),
/* REQUIRED */ $._encodeBigInt(value.privateExponent, $.BER),
/* REQUIRED */ $._encodeBigInt(value.prime1, $.BER),
/* REQUIRED */ $._encodeBigInt(value.prime2, $.BER),
/* REQUIRED */ $._encodeBigInt(value.exponent1, $.BER),
/* REQUIRED */ $._encodeBigInt(value.exponent2, $.BER),
/* REQUIRED */ $._encodeBigInt(value.coefficient, $.BER),
/* IF_ABSENT */ 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;
/* END_OF_SYMBOL_DEFINITION _encode_RSAPrivateKey */
/* eslint-enable */
//# sourceMappingURL=RSAPrivateKey.ta.js.map