diff options
author | Marvin Hagemeister <marvin@deno.com> | 2024-11-19 01:39:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-19 01:39:40 +0100 |
commit | df1d36324ffd4f687c406e412f9255bf7a9d8a61 (patch) | |
tree | c9ed10db694d05bc0ce0dab6ddadf2d3058fb370 /ext/node/polyfills/internal/crypto/keygen.ts | |
parent | 594a99817cbe44553b2c288578fbba8e1e9c1907 (diff) |
fix(node/crypto): support promisify on generateKeyPair (#26913)
Calling `promisify(generateKeyPair)` didn't work as expected. It
requires a custom promisify implementation.
This was easy to fix thanks to the excellent debugging investigation in
https://github.com/denoland/deno/issues/26910
Fixes https://github.com/denoland/deno/issues/26910
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/node/polyfills/internal/crypto/keygen.ts')
-rw-r--r-- | ext/node/polyfills/internal/crypto/keygen.ts | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/ext/node/polyfills/internal/crypto/keygen.ts b/ext/node/polyfills/internal/crypto/keygen.ts index 44bfd8327..b023ab106 100644 --- a/ext/node/polyfills/internal/crypto/keygen.ts +++ b/ext/node/polyfills/internal/crypto/keygen.ts @@ -30,6 +30,7 @@ import { import { Buffer } from "node:buffer"; import { KeyFormat, KeyType } from "ext:deno_node/internal/crypto/types.ts"; import process from "node:process"; +import { promisify } from "node:util"; import { op_node_generate_dh_group_key, @@ -570,7 +571,15 @@ export function generateKeyPair( privateKey: any, ) => void, ) { - createJob(kAsync, type, options).then((pair) => { + _generateKeyPair(type, options) + .then( + (res) => callback(null, res.publicKey, res.privateKey), + (err) => callback(err, null, null), + ); +} + +function _generateKeyPair(type: string, options: unknown) { + return createJob(kAsync, type, options).then((pair) => { const privateKeyHandle = op_node_get_private_key_from_pair(pair); const publicKeyHandle = op_node_get_public_key_from_pair(pair); @@ -589,12 +598,15 @@ export function generateKeyPair( } } - callback(null, publicKey, privateKey); - }).catch((err) => { - callback(err, null, null); + return { publicKey, privateKey }; }); } +Object.defineProperty(generateKeyPair, promisify.custom, { + enumerable: false, + value: _generateKeyPair, +}); + export interface KeyPairKeyObjectResult { publicKey: KeyObject; privateKey: KeyObject; |