Skip to content

Commit

Permalink
Support BigInt/Uint64Array in crypto.getRandomValues
Browse files Browse the repository at this point in the history
The check for "integer arrays" is to prevent people from using
getRandomValues with floating-point arrays, which doesn't work as people
might expect. However, the check was not updated when Chrome gained
support for BigInt64Array and BigUint64Array, which do work as expected.
This allows code fragments such as

    const b = new BigInt64Array(10);
    crypto.getRandomValues(b);

See w3c/webcrypto#255 for the spec issue.

Bug: 1225765
Change-Id: I338ecc5594492e6f329580f4e8f04d367f866361
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3002049
Reviewed-by: Mike West <[email protected]>
Commit-Queue: Timothy Gu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#898924}
  • Loading branch information
TimothyGu authored and chromium-wpt-export-bot committed Jul 6, 2021
1 parent a2ccb30 commit 6820081
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions WebCryptoAPI/getRandomValues-bigint.tentative.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Tentative: see https://github.com/w3c/webcrypto/issues/255

const arrays = [
'BigInt64Array',
'BigUint64Array',
];

for (const array of arrays) {
const ctor = globalThis[array];

test(function() {
assert_equals(self.crypto.getRandomValues(new ctor(8)).constructor,
ctor, "crypto.getRandomValues(new " + array + "(8))")
}, "Integer array: " + array);

test(function() {
const maxlength = 65536 / ctor.BYTES_PER_ELEMENT;
assert_throws_dom("QuotaExceededError", function() {
self.crypto.getRandomValues(new ctor(maxlength + 1))
}, "crypto.getRandomValues length over 65536")
}, "Large length: " + array);

test(function() {
assert_true(self.crypto.getRandomValues(new ctor(0)).length == 0)
}, "Null arrays: " + array);
}

0 comments on commit 6820081

Please sign in to comment.