@hazae41/x509
Version:
Zero-copy X.509 certificates in pure modern TypeScript
40 lines (36 loc) • 1.31 kB
JavaScript
;
var asn1 = require('@hazae41/asn1');
var oids = require('../../oids/oids.cjs');
class RsaPublicKey {
publicExponent;
modulus;
static oid = oids.OIDs.keys.rsaEncryption;
constructor(publicExponent, modulus) {
this.publicExponent = publicExponent;
this.modulus = modulus;
}
toDER() {
return asn1.Sequence.DER.create(undefined, [
this.publicExponent,
this.modulus
]).toDER();
}
toJSON() {
const publicExponent = this.publicExponent.value.toString(16);
const modulus = this.modulus.value.toString(16);
return { publicExponent, modulus };
}
static fromJSON(json) {
const publicExponent = asn1.Integer.create(undefined, BigInt("0x" + json.publicExponent));
const modulus = asn1.Integer.create(undefined, BigInt("0x" + json.modulus));
return new this(publicExponent, modulus);
}
static resolveOrThrow(parent) {
const cursor = parent.subAsOrThrow(asn1.Sequence.DER);
const publicExponent = cursor.readAsOrThrow(asn1.Integer.DER);
const modulus = cursor.readAsOrThrow(asn1.Integer.DER);
return new RsaPublicKey(publicExponent, modulus);
}
}
exports.RsaPublicKey = RsaPublicKey;
//# sourceMappingURL=public.cjs.map