lib: add and test [EnforceRange] in webcrypto dictionaries · nodejs/node@7f7df06 · GitHub
Skip to content

Commit 7f7df06

Browse files
panvaaduh95
authored andcommitted
lib: add and test [EnforceRange] in webcrypto dictionaries
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #65091 Refs: w3c/webcrypto#555 Refs: WICG/webcrypto-modern-algos#65 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent fa52f11 commit 7f7df06

3 files changed

Lines changed: 139 additions & 1 deletion

File tree

lib/internal/crypto/webcrypto.js

Lines changed: 6 additions & 1 deletion
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
8+
const assert = require('assert');
9+
const { SubtleCrypto } = globalThis;
10+
const { subtle } = globalThis.crypto;
11+
12+
const algorithm = {
13+
name: 'HKDF',
14+
hash: 'SHA-256',
15+
info: new Uint8Array(),
16+
salt: new Uint8Array(32),
17+
};
18+
const invalidLength = 2 ** 32;
19+
const expectedError = {
20+
code: 'ERR_OUT_OF_RANGE',
21+
name: 'TypeError',
22+
};
23+
24+
assert.throws(
25+
() => SubtleCrypto.supports('deriveBits', algorithm, invalidLength),
26+
expectedError);
27+
28+
(async () => {
29+
const key = await subtle.importKey(
30+
'raw', new Uint8Array(32), 'HKDF', false, ['deriveBits']);
31+
32+
await assert.rejects(
33+
subtle.deriveBits(algorithm, key, invalidLength),
34+
expectedError);
35+
})().then(common.mustCall());

test/parallel/test-webcrypto-webidl.js

Lines changed: 98 additions & 0 deletions

0 commit comments

Comments
 (0)