mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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:
parent
41c6ac126c
commit
1db84f28f5
4
types/node-forge/index.d.ts
vendored
4
types/node-forge/index.d.ts
vendored
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user