diff options
author | Luca Casonato <hello@lcas.dev> | 2024-08-08 11:35:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-08 15:05:29 +0530 |
commit | 93d479252b5a18e6e782c74b808240bd3ef036bd (patch) | |
tree | 4c8b83797fb0e30d1ce3fcebad3fbde6cf33ef1d /ext/node/polyfills/internal/crypto/diffiehellman.ts | |
parent | 507e5b74ff21161ba8bd947d7d9cee317c0af379 (diff) |
fix(ext/node): add crypto.diffieHellman (#24938)
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Closes #21806
Diffstat (limited to 'ext/node/polyfills/internal/crypto/diffiehellman.ts')
-rw-r--r-- | ext/node/polyfills/internal/crypto/diffiehellman.ts | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/ext/node/polyfills/internal/crypto/diffiehellman.ts b/ext/node/polyfills/internal/crypto/diffiehellman.ts index 16a1f2498..a439306a9 100644 --- a/ext/node/polyfills/internal/crypto/diffiehellman.ts +++ b/ext/node/polyfills/internal/crypto/diffiehellman.ts @@ -7,6 +7,7 @@ import { op_node_dh_compute_secret, op_node_dh_keys_generate_and_export, + op_node_diffie_hellman, op_node_ecdh_compute_public_key, op_node_ecdh_compute_secret, op_node_ecdh_encode_pubkey, @@ -40,7 +41,12 @@ import type { BinaryToTextEncoding, ECDHKeyFormat, } from "ext:deno_node/internal/crypto/types.ts"; -import { KeyObject } from "ext:deno_node/internal/crypto/keys.ts"; +import { + getKeyObjectHandle, + kConsumePrivate, + kConsumePublic, + KeyObject, +} from "ext:deno_node/internal/crypto/keys.ts"; import type { BufferEncoding } from "ext:deno_node/_global.d.ts"; const DH_GENERATOR = 2; @@ -1305,11 +1311,14 @@ export class ECDH { } } -export function diffieHellman(_options: { +export function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject; }): Buffer { - notImplemented("crypto.diffieHellman"); + const privateKey = getKeyObjectHandle(options.privateKey, kConsumePrivate); + const publicKey = getKeyObjectHandle(options.publicKey, kConsumePublic); + const bytes = op_node_diffie_hellman(privateKey, publicKey); + return Buffer.from(bytes); } export default { |