@hazae41/x509
Version:
Zero-copy X.509 certificates in pure modern TypeScript
38 lines (35 loc) • 1.26 kB
JavaScript
import { Sequence, Integer } from '@hazae41/asn1';
import { OIDs } from '../../oids/oids.mjs';
class RsaPublicKey {
publicExponent;
modulus;
static oid = OIDs.keys.rsaEncryption;
constructor(publicExponent, modulus) {
this.publicExponent = publicExponent;
this.modulus = modulus;
}
toDER() {
return 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 = Integer.create(undefined, BigInt("0x" + json.publicExponent));
const modulus = Integer.create(undefined, BigInt("0x" + json.modulus));
return new this(publicExponent, modulus);
}
static resolveOrThrow(parent) {
const cursor = parent.subAsOrThrow(Sequence.DER);
const publicExponent = cursor.readAsOrThrow(Integer.DER);
const modulus = cursor.readAsOrThrow(Integer.DER);
return new RsaPublicKey(publicExponent, modulus);
}
}
export { RsaPublicKey };
//# sourceMappingURL=public.mjs.map