node-forge: Fix type of pki.rsa.setPublicKey() (#37081)

- Replace the `any`s by proper types.
- Return an `pki.rsa.PublicKey` instead of `pki.PublicKey` to be
  more specific (the latter also allows ed25519).
- Make `pki.setRsaPublicKey` an alias of `rsa.setPublicKey`.
This commit is contained in:
Tim Düsterhus 2019-08-05 18:52:34 +02:00 committed by Nathan Shively-Sanders
parent 41c6ac126c
commit 1db84f28f5
2 changed files with 3 additions and 2 deletions

View File

@ -114,7 +114,7 @@ declare module "node-forge" {
algorithm?: string;
}
function setPublicKey(n: any, e: any): any;
function setPublicKey(n: jsbn.BigInteger, e: jsbn.BigInteger): PublicKey;
function generateKeyPair(bits?: number, e?: number, callback?: (err: Error, keypair: KeyPair) => void): KeyPair;
function generateKeyPair(options?: GenerateKeyPairOptions, callback?: (err: Error, keypair: KeyPair) => void): KeyPair;
@ -314,7 +314,7 @@ declare module "node-forge" {
function publicKeyToRSAPublicKey(publicKey: PublicKey): any;
function setRsaPublicKey(n: jsbn.BigInteger, e: jsbn.BigInteger): PublicKey;
type setRsaPublicKey = typeof rsa.setPublicKey;
function wrapRsaPrivateKey(privateKey: asn1.Asn1): asn1.Asn1;
}

View File

@ -1,6 +1,7 @@
import * as forge from 'node-forge';
let keypair = forge.pki.rsa.generateKeyPair({ bits: 512 });
forge.pki.rsa.setPublicKey(keypair.privateKey.n, keypair.privateKey.e);
let privateKeyPem = forge.pki.privateKeyToPem(keypair.privateKey);
let publicKeyPem = forge.pki.publicKeyToPem(keypair.publicKey);
let key = forge.pki.decryptRsaPrivateKey(privateKeyPem);