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 <benjamingr@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
  • Loading branch information
gc authored and danielleadams committed Oct 12, 2021
1 parent 5f3f3a5 commit a8926d1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/crypto/ec.js
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
54 changes: 54 additions & 0 deletions test/parallel/test-webcrypto-ed25519-ed448.js
@@ -1,3 +1,4 @@
// Flags: --expose-internals
'use strict';

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

const { internalBinding } = require('internal/test/binding');
const { DOMException } = internalBinding('messaging');

async function generateKey(namedCurve) {
return subtle.generateKey(
{
Expand Down Expand Up @@ -429,3 +433,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 a8926d1

Please sign in to comment.