summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/crypto
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-03-21 14:11:54 +0530
committerGitHub <noreply@github.com>2024-03-21 14:11:54 +0530
commit1f60b8af97b15cb8e33f68c44f602cf69d79bd7a (patch)
treeb7ab11749fc4e20a9b4589ba2b97bd64991bb9f0 /ext/node/polyfills/internal/crypto
parent210f2911ce3f498524c0354e8f60d62e3dbc39ed (diff)
fix(ext/node): ECDH.publicKey() point encoding (#23013)
Diffstat (limited to 'ext/node/polyfills/internal/crypto')
-rw-r--r--ext/node/polyfills/internal/crypto/diffiehellman.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/ext/node/polyfills/internal/crypto/diffiehellman.ts b/ext/node/polyfills/internal/crypto/diffiehellman.ts
index da7907734..6058433ba 100644
--- a/ext/node/polyfills/internal/crypto/diffiehellman.ts
+++ b/ext/node/polyfills/internal/crypto/diffiehellman.ts
@@ -9,6 +9,7 @@ import {
op_node_dh_generate2,
op_node_ecdh_compute_public_key,
op_node_ecdh_compute_secret,
+ op_node_ecdh_encode_pubkey,
op_node_ecdh_generate_keys,
op_node_gen_prime,
} from "ext:core/ops";
@@ -1239,7 +1240,7 @@ export class ECDH {
format: ECDHKeyFormat = "uncompressed",
): Buffer | string {
this.#pubbuf = Buffer.alloc(
- format.trim() == "compressed"
+ format == "compressed"
? this.#curve.publicKeySizeCompressed
: this.#curve.publicKeySize,
);
@@ -1269,12 +1270,17 @@ export class ECDH {
getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
getPublicKey(
encoding?: BinaryToTextEncoding,
- _format?: ECDHKeyFormat,
+ format: ECDHKeyFormat = "uncompressed",
): Buffer | string {
+ const pubbuf = Buffer.from(op_node_ecdh_encode_pubkey(
+ this.#curve.name,
+ this.#pubbuf,
+ format == "compressed",
+ ));
if (encoding !== undefined) {
- return this.#pubbuf.toString(encoding);
+ return pubbuf.toString(encoding);
}
- return this.#pubbuf;
+ return pubbuf;
}
setPrivateKey(privateKey: ArrayBufferView): void;