@hazae41/x509
Version:
Zero-copy X.509 certificates in pure modern TypeScript
1 lines • 2.56 kB
Source Map (JSON)
{"version":3,"file":"public.mjs","sources":["../../../../../src/mods/keys/rsa/public.ts"],"sourcesContent":["import { DERCursor, DERTriplet, Integer, Sequence } from \"@hazae41/asn1\";\nimport { OIDs } from \"mods/oids/oids.js\";\n\nexport interface RsaPublicKeyJSON {\n readonly publicExponent: string,\n readonly modulus: string\n}\n\nexport class RsaPublicKey {\n\n static oid = OIDs.keys.rsaEncryption\n\n constructor(\n readonly publicExponent: Integer,\n readonly modulus: Integer\n ) { }\n\n toDER(): DERTriplet {\n return Sequence.DER.create(undefined, [\n this.publicExponent,\n this.modulus\n ] as const).toDER()\n }\n\n toJSON(): RsaPublicKeyJSON {\n const publicExponent = this.publicExponent.value.toString(16)\n const modulus = this.modulus.value.toString(16)\n\n return { publicExponent, modulus }\n }\n\n static fromJSON(json: RsaPublicKeyJSON) {\n const publicExponent = Integer.create(undefined, BigInt(\"0x\" + json.publicExponent))\n const modulus = Integer.create(undefined, BigInt(\"0x\" + json.modulus))\n\n return new this(publicExponent, modulus)\n }\n\n static resolveOrThrow(parent: DERCursor) {\n const cursor = parent.subAsOrThrow(Sequence.DER)\n const publicExponent = cursor.readAsOrThrow(Integer.DER)\n const modulus = cursor.readAsOrThrow(Integer.DER)\n\n return new RsaPublicKey(publicExponent, modulus)\n }\n\n}"],"names":[],"mappings":";;;MAQa,YAAY,CAAA;AAKZ,IAAA,cAAA;AACA,IAAA,OAAA;IAJX,OAAO,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa;IAEpC,WAAA,CACW,cAAuB,EACvB,OAAgB,EAAA;QADhB,IAAA,CAAA,cAAc,GAAd,cAAc;QACd,IAAA,CAAA,OAAO,GAAP,OAAO;IACd;IAEJ,KAAK,GAAA;AACH,QAAA,OAAO,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE;AACpC,YAAA,IAAI,CAAC,cAAc;AACnB,YAA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