Skip to content

Commit 28f711b

Browse files
gcpanva
authored andcommitted
crypto: remove incorrect constructor invocation
PR-URL: #40300 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent 0d2b6ac commit 28f711b

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

lib/internal/crypto/ec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ function ecdsaSignVerify(key, data, { name, hash }, signature) {
482482
// Fall through
483483
case 'NODE-ED448':
484484
if (hash !== undefined)
485-
throw new lazyDOMException(`Hash is not permitted for ${name}`);
485+
throw lazyDOMException(`Hash is not permitted for ${name}`);
486486
break;
487487
default:
488488
if (hash === undefined)

test/parallel/test-webcrypto-ed25519-ed448.js

+50
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,53 @@ assert.rejects(
429429
}
430430
}
431431
}
432+
433+
{
434+
// See: https://github.com/nodejs/node/pull/40300
435+
for (const namedCurve of ['NODE-ED25519', 'NODE-ED448']) {
436+
assert.rejects(
437+
(async () => {
438+
const { privateKey } = await generateKey(namedCurve);
439+
return subtle.sign(
440+
{
441+
name: namedCurve,
442+
hash: 'SHA-256'
443+
},
444+
privateKey,
445+
Buffer.from('abc')
446+
);
447+
})(),
448+
(err) => {
449+
assert.strictEqual(err.message, `Hash is not permitted for ${namedCurve}`);
450+
assert(err instanceof DOMException);
451+
return true;
452+
}).then(common.mustCall());
453+
454+
assert.rejects(
455+
(async () => {
456+
const { publicKey, privateKey } = await generateKey(namedCurve);
457+
const signature = await subtle.sign(
458+
{
459+
name: namedCurve,
460+
},
461+
privateKey,
462+
Buffer.from('abc')
463+
).catch(common.mustNotCall());
464+
465+
return subtle.verify(
466+
{
467+
name: namedCurve,
468+
hash: 'SHA-256',
469+
},
470+
publicKey,
471+
signature,
472+
Buffer.from('abc')
473+
);
474+
})(),
475+
(err) => {
476+
assert.strictEqual(err.message, `Hash is not permitted for ${namedCurve}`);
477+
assert(err instanceof DOMException);
478+
return true;
479+
}).then(common.mustCall());
480+
}
481+
}

0 commit comments

Comments
 (0)