From 1171c549526ba9eaa070f7d02431748f12fddf9d Mon Sep 17 00:00:00 2001 From: Levente Kurusa Date: Tue, 16 May 2023 00:07:58 +0200 Subject: feat(node/crypto): Builtin Diffie-Hellman Groups (#19137) Towards #18455 --- cli/tests/node_compat/config.jsonc | 1 + .../test/parallel/test-crypto-dh-shared.js | 22 ++++++++++++++++++ .../node_compat/test/parallel/test-crypto-dh.js | 26 +++++++++++----------- 3 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 cli/tests/node_compat/test/parallel/test-crypto-dh-shared.js (limited to 'cli/tests') diff --git a/cli/tests/node_compat/config.jsonc b/cli/tests/node_compat/config.jsonc index 8631efcad..36b22a672 100644 --- a/cli/tests/node_compat/config.jsonc +++ b/cli/tests/node_compat/config.jsonc @@ -240,6 +240,7 @@ "test-console-sync-write-error.js", "test-console-table.js", "test-console-tty-colors.js", + "test-crypto-dh-shared.js", "test-crypto-dh.js", "test-crypto-hkdf.js", "test-crypto-hmac.js", diff --git a/cli/tests/node_compat/test/parallel/test-crypto-dh-shared.js b/cli/tests/node_compat/test/parallel/test-crypto-dh-shared.js new file mode 100644 index 000000000..5ab6fe465 --- /dev/null +++ b/cli/tests/node_compat/test/parallel/test-crypto-dh-shared.js @@ -0,0 +1,22 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually + +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +const assert = require('assert'); +const crypto = require('crypto'); + +const alice = crypto.createDiffieHellmanGroup('modp5'); +const bob = crypto.createDiffieHellmanGroup('modp5'); +alice.generateKeys(); +bob.generateKeys(); +const aSecret = alice.computeSecret(bob.getPublicKey()).toString('hex'); +const bSecret = bob.computeSecret(alice.getPublicKey()).toString('hex'); +assert.strictEqual(aSecret, bSecret); diff --git a/cli/tests/node_compat/test/parallel/test-crypto-dh.js b/cli/tests/node_compat/test/parallel/test-crypto-dh.js index b436207ac..bcf0c6764 100644 --- a/cli/tests/node_compat/test/parallel/test-crypto-dh.js +++ b/cli/tests/node_compat/test/parallel/test-crypto-dh.js @@ -187,21 +187,21 @@ if (false) { message: 'The "curve" argument must be of type string. ' + 'Received undefined' }); - - assert.throws( - function() { - crypto.getDiffieHellman('unknown-group'); - }, - { - name: 'Error', - code: 'ERR_CRYPTO_UNKNOWN_DH_GROUP', - message: 'Unknown DH group' - }, - 'crypto.getDiffieHellman(\'unknown-group\') ' + - 'failed to throw the expected error.' - ); } +assert.throws( + function() { + crypto.getDiffieHellman('unknown-group'); + }, + { + name: 'Error', + code: 'ERR_CRYPTO_UNKNOWN_DH_GROUP', + message: 'Unknown DH group' + }, + 'crypto.getDiffieHellman(\'unknown-group\') ' + + 'failed to throw the expected error.' +); + assert.throws( () => crypto.createDiffieHellman('', true), { -- cgit v1.2.3