mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65091 Refs: https://github.com/w3c/webcrypto/pull/555 Refs: https://github.com/WICG/webcrypto-modern-algos/pull/65 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: James M Snell <jasnell@gmail.com>
36 lines
790 B
JavaScript
36 lines
790 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const { SubtleCrypto } = globalThis;
|
|
const { subtle } = globalThis.crypto;
|
|
|
|
const algorithm = {
|
|
name: 'HKDF',
|
|
hash: 'SHA-256',
|
|
info: new Uint8Array(),
|
|
salt: new Uint8Array(32),
|
|
};
|
|
const invalidLength = 2 ** 32;
|
|
const expectedError = {
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
name: 'TypeError',
|
|
};
|
|
|
|
assert.throws(
|
|
() => SubtleCrypto.supports('deriveBits', algorithm, invalidLength),
|
|
expectedError);
|
|
|
|
(async () => {
|
|
const key = await subtle.importKey(
|
|
'raw', new Uint8Array(32), 'HKDF', false, ['deriveBits']);
|
|
|
|
await assert.rejects(
|
|
subtle.deriveBits(algorithm, key, invalidLength),
|
|
expectedError);
|
|
})().then(common.mustCall());
|