-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: remove incorrect constructor invocation
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
test/parallel/test-crypto-subtle-hash-constructor-error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})) |