From 1baf50cee1c0905df45a8a3400163e80dad4abe0 Mon Sep 17 00:00:00 2001 From: gc <30398469+gc@users.noreply.github.com> Date: Mon, 4 Oct 2021 19:47:22 +1100 Subject: [PATCH] crypto: remove incorrect constructor invocation --- lib/internal/crypto/ec.js | 2 +- ...st-crypto-subtle-hash-constructor-error.js | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-crypto-subtle-hash-constructor-error.js diff --git a/lib/internal/crypto/ec.js b/lib/internal/crypto/ec.js index c684d6c66af26a..b64922bcdc883f 100644 --- a/lib/internal/crypto/ec.js +++ b/lib/internal/crypto/ec.js @@ -482,7 +482,7 @@ function ecdsaSignVerify(key, data, { name, hash }, signature) { // Fall through case 'NODE-ED448': if (hash !== undefined) - throw new lazyDOMException(`Hash is not permitted for ${name}`); + throw lazyDOMException(`Hash is not permitted for ${name}`); break; default: if (hash === undefined) diff --git a/test/parallel/test-crypto-subtle-hash-constructor-error.js b/test/parallel/test-crypto-subtle-hash-constructor-error.js new file mode 100644 index 00000000000000..0d7f4aee1e7982 --- /dev/null +++ b/test/parallel/test-crypto-subtle-hash-constructor-error.js @@ -0,0 +1,36 @@ +'use strict'; + +const common = require('../common'); + +if (!common.hasCrypto) + common.skip('missing crypto'); + +const assert = require('assert'); +const crypto = require('crypto').webcrypto; + + +async function generateKey() { + const { privateKey } = await crypto.subtle.generateKey( + { + name: 'NODE-ED25519', + namedCurve: 'NODE-ED25519' + }, + true, + ['sign', 'verify'] + ); + const signature = await crypto.subtle.sign( + { + name: 'NODE-ED25519', + hash: 'SHA-256' + }, + privateKey, + '-' + ); + return signature; +} + +generateKey().catch(common.mustCall((err) => { + assert.strictEqual(err.name, 'DOMException'); + assert.strictEqual(err.message, 'Hash is not permitted for NODE-ED25519'); + assert.ok(err instanceof DOMException); +})) \ No newline at end of file