Skip to content

Commit

Permalink
crypto: remove incorrect constructor invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Oct 4, 2021
1 parent 1811396 commit 1baf50c
Show file tree
Hide file tree
Showing 2 changed files with 37 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
36 changes: 36 additions & 0 deletions test/parallel/test-crypto-subtle-hash-constructor-error.js
Original file line number Diff line number Diff line change
@@ -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);
}))

0 comments on commit 1baf50c

Please sign in to comment.