Skip to content

Commit

Permalink
crypto: remove incorrect constructor invocation
Browse files Browse the repository at this point in the history
PR-URL: #40300
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
  • Loading branch information
gc authored and panva committed Oct 5, 2021
1 parent 0d2b6ac commit 28f711b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/crypto/ec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 50 additions & 0 deletions test/parallel/test-webcrypto-ed25519-ed448.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,53 @@ assert.rejects(
}
}
}

{
// See: https://github.com/nodejs/node/pull/40300
for (const namedCurve of ['NODE-ED25519', 'NODE-ED448']) {
assert.rejects(
(async () => {
const { privateKey } = await generateKey(namedCurve);
return subtle.sign(
{
name: namedCurve,
hash: 'SHA-256'
},
privateKey,
Buffer.from('abc')
);
})(),
(err) => {
assert.strictEqual(err.message, `Hash is not permitted for ${namedCurve}`);
assert(err instanceof DOMException);
return true;
}).then(common.mustCall());

assert.rejects(
(async () => {
const { publicKey, privateKey } = await generateKey(namedCurve);
const signature = await subtle.sign(
{
name: namedCurve,
},
privateKey,
Buffer.from('abc')
).catch(common.mustNotCall());

return subtle.verify(
{
name: namedCurve,
hash: 'SHA-256',
},
publicKey,
signature,
Buffer.from('abc')
);
})(),
(err) => {
assert.strictEqual(err.message, `Hash is not permitted for ${namedCurve}`);
assert(err instanceof DOMException);
return true;
}).then(common.mustCall());
}
}

0 comments on commit 28f711b

Please sign in to comment.