Skip to content

Commit

Permalink
Don't use return value of crypto.getRandomValues
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Dec 13, 2023
1 parent b7db32c commit 7c4239a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Reflect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2005,9 +2005,17 @@ namespace Reflect {

function GenRandomBytes(size: number): BufferLike {
if (typeof Uint8Array === "function") {
if (typeof crypto !== "undefined") return crypto.getRandomValues(new Uint8Array(size)) as Uint8Array;
if (typeof msCrypto !== "undefined") return msCrypto.getRandomValues(new Uint8Array(size)) as Uint8Array;
return FillRandomBytes(new Uint8Array(size), size);
const array = new Uint8Array(size);
if (typeof crypto !== "undefined") {
crypto.getRandomValues(array);
}
else if (typeof msCrypto !== "undefined") {
msCrypto.getRandomValues(array);
}
else {
FillRandomBytes(array, size);
}
return array;
}
return FillRandomBytes(new Array(size), size);
}
Expand Down

0 comments on commit 7c4239a

Please sign in to comment.