diff options
author | Michaël Zasso <targos@protonmail.com> | 2021-07-19 13:55:53 +0200 |
---|---|---|
committer | Node.js GitHub Bot <github-bot@iojs.org> | 2021-07-23 08:34:25 +0000 |
commit | 56a7e0aa90410c79b4946678851cb9698ef5b624 (patch) | |
tree | 31936626a708dba2daae092236a3a4398bd8db9f /test/parallel/test-webcrypto-random.js | |
parent | ab73d95aceb8aab0177c6975db89b648344cc575 (diff) | |
download | node-new-56a7e0aa90410c79b4946678851cb9698ef5b624.tar.gz |
crypto: support Big(U)Int64Array in getRandomValues
Refs: https://github.com/w3c/webcrypto/issues/255
Fixes: https://github.com/nodejs/node/issues/39442
PR-URL: https://github.com/nodejs/node/pull/39443
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Diffstat (limited to 'test/parallel/test-webcrypto-random.js')
-rw-r--r-- | test/parallel/test-webcrypto-random.js | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/test/parallel/test-webcrypto-random.js b/test/parallel/test-webcrypto-random.js index fd933915c5..f2bf2c396f 100644 --- a/test/parallel/test-webcrypto-random.js +++ b/test/parallel/test-webcrypto-random.js @@ -9,8 +9,15 @@ const { Buffer } = require('buffer'); const assert = require('assert'); const { getRandomValues } = require('crypto').webcrypto; -[undefined, null, '', 1, {}, []].forEach((i) => { - assert.throws(() => getRandomValues(i), { code: 17 }); +[ + undefined, null, '', 1, {}, [], + new Float32Array(1), + new Float64Array(1), +].forEach((i) => { + assert.throws( + () => getRandomValues(i), + { name: 'TypeMismatchError', code: 17 }, + ); }); { @@ -18,32 +25,27 @@ const { getRandomValues } = require('crypto').webcrypto; getRandomValues(buf); } -{ - const buf = new Uint8Array(new Array(10).fill(0)); - const before = Buffer.from(buf).toString('hex'); - getRandomValues(buf); - const after = Buffer.from(buf).toString('hex'); - assert.notStrictEqual(before, after); -} - -{ - const buf = new Uint16Array(new Array(10).fill(0)); - const before = Buffer.from(buf).toString('hex'); - getRandomValues(buf); - const after = Buffer.from(buf).toString('hex'); - assert.notStrictEqual(before, after); -} +const intTypedConstructors = [ + Int8Array, + Int16Array, + Int32Array, + Uint8Array, + Uint16Array, + Uint32Array, + BigInt64Array, + BigUint64Array, +]; -{ - const buf = new Uint32Array(new Array(10).fill(0)); - const before = Buffer.from(buf).toString('hex'); +for (const ctor of intTypedConstructors) { + const buf = new ctor(10); + const before = Buffer.from(buf.buffer).toString('hex'); getRandomValues(buf); - const after = Buffer.from(buf).toString('hex'); + const after = Buffer.from(buf.buffer).toString('hex'); assert.notStrictEqual(before, after); } { - const buf = new Uint16Array(new Array(10).fill(0)); + const buf = new Uint16Array(10); const before = Buffer.from(buf).toString('hex'); getRandomValues(new DataView(buf.buffer)); const after = Buffer.from(buf).toString('hex'); |