crypto: adjust types for getRandomValues · nodejs/node@188c3ab · GitHub
Skip to content

Commit 188c3ab

Browse files
LiviaMedeirosdanielleadams
authored andcommitted
crypto: adjust types for getRandomValues
prevents Web Crypto API's getRandomValues from accepting DataView Fixes: #41480 Refs: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues PR-URL: #41481 Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5f0a017 commit 188c3ab

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

doc/api/webcrypto.md

Lines changed: 5 additions & 2 deletions

lib/internal/crypto/random.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const {
5050
const {
5151
isArrayBufferView,
5252
isAnyArrayBuffer,
53+
isTypedArray,
5354
isFloat32Array,
5455
isFloat64Array,
5556
} = require('internal/util/types');
@@ -307,7 +308,7 @@ function onJobDone(buf, callback, error) {
307308
// not allowed to exceed 65536 bytes, and can only
308309
// be an integer-type TypedArray.
309310
function getRandomValues(data) {
310-
if (!isArrayBufferView(data) ||
311+
if (!isTypedArray(data) ||
311312
isFloat32Array(data) ||
312313
isFloat64Array(data)) {
313314
// Ordinarily this would be an ERR_INVALID_ARG_TYPE. However,

test/parallel/test-webcrypto-random.js

Lines changed: 3 additions & 1 deletion

0 commit comments

Comments
 (0)