Fix filling larger width TypedArrays

This commit is contained in:
Emil Bay 2020-06-24 14:55:46 +02:00 committed by GitHub
parent 919896d2bb
commit 74a1067746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,12 +6,12 @@ var randombytes = (function () {
function browserBytes (out, n) {
for (let i = 0; i < n; i += QUOTA) {
crypto.getRandomValues(out.subarray(i, i + Math.min(n - i, QUOTA)))
crypto.getRandomValues(new Uint8Array(out.buffer, i, Math.min(n - i, QUOTA)))
}
}
function nodeBytes (out, n) {
out.set(crypto.randomBytes(n))
new Uint8Array(out.buffer, 0, n).set(crypto.randomBytes(n))
}
function noImpl () {
@ -36,5 +36,5 @@ Object.defineProperty(module.exports, 'randombytes', {
module.exports.randombytes_buf = function (out) {
assert(out, 'out must be given')
randombytes(out, out.length)
randombytes(out, out.byteLength)
}