@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
238 lines (237 loc) • 8.87 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
/**
* @summary RSAPrivateKeyObject
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* RSAPrivateKeyObject ::= SEQUENCE {
* modulus [0] INTEGER OPTIONAL, -- n
* publicExponent [1] INTEGER OPTIONAL, -- e
* privateExponent [2] INTEGER OPTIONAL, -- d
* prime1 [3] INTEGER OPTIONAL, -- p
* prime2 [4] INTEGER OPTIONAL, -- q
* exponent1 [5] INTEGER OPTIONAL, -- d mod (p-1)
* exponent2 [6] INTEGER OPTIONAL, -- d mod (q-1)
* coefficient [7] INTEGER OPTIONAL -- inv(q) mod p
* } (CONSTRAINED BY {-- must be possible to reconstruct modulus and privateExponent from
* -- selected fields --})
* ```
*
*/
export class RSAPrivateKeyObject {
modulus;
publicExponent;
privateExponent;
prime1;
prime2;
exponent1;
exponent2;
coefficient;
constructor(
/**
* @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) {
this.modulus = modulus;
this.publicExponent = publicExponent;
this.privateExponent = privateExponent;
this.prime1 = prime1;
this.prime2 = prime2;
this.exponent1 = exponent1;
this.exponent2 = exponent2;
this.coefficient = coefficient;
}
/**
* @summary Restructures an object into a RSAPrivateKeyObject
* @description
*
* This takes an `object` and converts it to a `RSAPrivateKeyObject`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `RSAPrivateKeyObject`.
* @returns {RSAPrivateKeyObject}
*/
static _from_object(_o) {
return new RSAPrivateKeyObject(_o.modulus, _o.publicExponent, _o.privateExponent, _o.prime1, _o.prime2, _o.exponent1, _o.exponent2, _o.coefficient);
}
}
/**
* @summary The Leading Root Component Types of RSAPrivateKeyObject
* @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
*/
export const _root_component_type_list_1_spec_for_RSAPrivateKeyObject = [
new $.ComponentSpec("modulus", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("publicExponent", true, $.hasTag(_TagClass.context, 1)),
new $.ComponentSpec("privateExponent", true, $.hasTag(_TagClass.context, 2)),
new $.ComponentSpec("prime1", true, $.hasTag(_TagClass.context, 3)),
new $.ComponentSpec("prime2", true, $.hasTag(_TagClass.context, 4)),
new $.ComponentSpec("exponent1", true, $.hasTag(_TagClass.context, 5)),
new $.ComponentSpec("exponent2", true, $.hasTag(_TagClass.context, 6)),
new $.ComponentSpec("coefficient", true, $.hasTag(_TagClass.context, 7)),
];
/**
* @summary The Trailing Root Component Types of RSAPrivateKeyObject
* @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
*/
export const _root_component_type_list_2_spec_for_RSAPrivateKeyObject = [];
/**
* @summary The Extension Addition Component Types of RSAPrivateKeyObject
* @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
*/
export const _extension_additions_list_spec_for_RSAPrivateKeyObject = [];
let _cached_decoder_for_RSAPrivateKeyObject = null;
/**
* @summary Decodes an ASN.1 element into a(n) RSAPrivateKeyObject
* @function
* @param {_Element} el The element being decoded.
* @returns {RSAPrivateKeyObject} The decoded data structure.
*/
export function _decode_RSAPrivateKeyObject(el) {
if (!_cached_decoder_for_RSAPrivateKeyObject) {
_cached_decoder_for_RSAPrivateKeyObject = function (el) {
let modulus;
let publicExponent;
let privateExponent;
let prime1;
let prime2;
let exponent1;
let exponent2;
let coefficient;
const callbacks = {
modulus: (_el) => {
modulus = $._decode_implicit(() => $._decodeInteger)(_el);
},
publicExponent: (_el) => {
publicExponent = $._decode_implicit(() => $._decodeInteger)(_el);
},
privateExponent: (_el) => {
privateExponent = $._decode_implicit(() => $._decodeInteger)(_el);
},
prime1: (_el) => {
prime1 = $._decode_implicit(() => $._decodeInteger)(_el);
},
prime2: (_el) => {
prime2 = $._decode_implicit(() => $._decodeInteger)(_el);
},
exponent1: (_el) => {
exponent1 = $._decode_implicit(() => $._decodeInteger)(_el);
},
exponent2: (_el) => {
exponent2 = $._decode_implicit(() => $._decodeInteger)(_el);
},
coefficient: (_el) => {
coefficient = $._decode_implicit(() => $._decodeInteger)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_RSAPrivateKeyObject, _extension_additions_list_spec_for_RSAPrivateKeyObject, _root_component_type_list_2_spec_for_RSAPrivateKeyObject, undefined);
return new RSAPrivateKeyObject(modulus, publicExponent, privateExponent, prime1, prime2, exponent1, exponent2, coefficient);
};
}
return _cached_decoder_for_RSAPrivateKeyObject(el);
}
let _cached_encoder_for_RSAPrivateKeyObject = null;
/**
* @summary Encodes a(n) RSAPrivateKeyObject into an ASN.1 Element.
* @function
* @param value The element being encoded.
* @param elGetter A function that can be used to get new ASN.1 elements.
* @returns {_Element} The RSAPrivateKeyObject, encoded as an ASN.1 Element.
*/
export function _encode_RSAPrivateKeyObject(value, elGetter) {
if (!_cached_encoder_for_RSAPrivateKeyObject) {
_cached_encoder_for_RSAPrivateKeyObject = function (value) {
return $._encodeSequence([]
.concat([
/* IF_ABSENT */ value.modulus === undefined
? undefined
: $._encode_implicit(_TagClass.context, 0, () => $._encodeInteger, $.BER)(value.modulus, $.BER),
/* IF_ABSENT */ value.publicExponent === undefined
? undefined
: $._encode_implicit(_TagClass.context, 1, () => $._encodeInteger, $.BER)(value.publicExponent, $.BER),
/* IF_ABSENT */ value.privateExponent === undefined
? undefined
: $._encode_implicit(_TagClass.context, 2, () => $._encodeInteger, $.BER)(value.privateExponent, $.BER),
/* IF_ABSENT */ value.prime1 === undefined
? undefined
: $._encode_implicit(_TagClass.context, 3, () => $._encodeInteger, $.BER)(value.prime1, $.BER),
/* IF_ABSENT */ value.prime2 === undefined
? undefined
: $._encode_implicit(_TagClass.context, 4, () => $._encodeInteger, $.BER)(value.prime2, $.BER),
/* IF_ABSENT */ value.exponent1 === undefined
? undefined
: $._encode_implicit(_TagClass.context, 5, () => $._encodeInteger, $.BER)(value.exponent1, $.BER),
/* IF_ABSENT */ value.exponent2 === undefined
? undefined
: $._encode_implicit(_TagClass.context, 6, () => $._encodeInteger, $.BER)(value.exponent2, $.BER),
/* IF_ABSENT */ value.coefficient === undefined
? undefined
: $._encode_implicit(_TagClass.context, 7, () => $._encodeInteger, $.BER)(value.coefficient, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_RSAPrivateKeyObject(value, elGetter);
}
/* eslint-enable */