Skip to content

Commit

Permalink
Merge pull request #152 from rbuckton/fix-GenRandomValues
Browse files Browse the repository at this point in the history
Don't use return value of crypto.getRandomValues
  • Loading branch information
rbuckton authored Dec 13, 2023
2 parents b7db32c + 7c4239a commit 1fce5c6
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 1fce5c6

Please sign in to comment.