Skip to content

Commit a8926d1

Browse files
gcdanielleadams
authored andcommitted
crypto: remove incorrect constructor invocation
PR-URL: #40300 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
1 parent 5f3f3a5 commit a8926d1

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-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

+54
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --expose-internals
12
'use strict';
23

34
const common = require('../common');
@@ -11,6 +12,9 @@ const {
1112
webcrypto: { subtle }
1213
} = require('crypto');
1314

15+
const { internalBinding } = require('internal/test/binding');
16+
const { DOMException } = internalBinding('messaging');
17+
1418
async function generateKey(namedCurve) {
1519
return subtle.generateKey(
1620
{
@@ -429,3 +433,53 @@ assert.rejects(
429433
}
430434
}
431435
}
436+
437+
{
438+
// See: https://github.com/nodejs/node/pull/40300
439+
for (const namedCurve of ['NODE-ED25519', 'NODE-ED448']) {
440+
assert.rejects(
441+
(async () => {
442+
const { privateKey } = await generateKey(namedCurve);
443+
return subtle.sign(
444+
{
445+
name: namedCurve,
446+
hash: 'SHA-256'
447+
},
448+
privateKey,
449+
Buffer.from('abc')
450+
);
451+
})(),
452+
(err) => {
453+
assert.strictEqual(err.message, `Hash is not permitted for ${namedCurve}`);
454+
assert(err instanceof DOMException);
455+
return true;
456+
}).then(common.mustCall());
457+
458+
assert.rejects(
459+
(async () => {
460+
const { publicKey, privateKey } = await generateKey(namedCurve);
461+
const signature = await subtle.sign(
462+
{
463+
name: namedCurve,
464+
},
465+
privateKey,
466+
Buffer.from('abc')
467+
).catch(common.mustNotCall());
468+
469+
return subtle.verify(
470+
{
471+
name: namedCurve,
472+
hash: 'SHA-256',
473+
},
474+
publicKey,
475+
signature,
476+
Buffer.from('abc')
477+
);
478+
})(),
479+
(err) => {
480+
assert.strictEqual(err.message, `Hash is not permitted for ${namedCurve}`);
481+
assert(err instanceof DOMException);
482+
return true;
483+
}).then(common.mustCall());
484+
}
485+
}

0 commit comments

Comments
 (0)