diff options
author | 2023-01-01 12:04:49 -0800 | |
---|---|---|
committer | 2023-01-01 12:04:49 -0800 | |
commit | 96438a4d58569abedccdfe6acff0ad6ed60bb5bc (patch) | |
tree | be97cd6fa6bdf0d135be0467f8919a60821ddb90 /src | |
parent | 5b3cf8bec56e7c13d2cce557bab8e203be729006 (diff) | |
download | bun-96438a4d58569abedccdfe6acff0ad6ed60bb5bc.tar.gz bun-96438a4d58569abedccdfe6acff0ad6ed60bb5bc.tar.zst bun-96438a4d58569abedccdfe6acff0ad6ed60bb5bc.zip |
test crypto.randomBytes returns a Buffer
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/crypto.exports.js | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/src/bun.js/crypto.exports.js b/src/bun.js/crypto.exports.js index cd06879bb..6362a6ea1 100644 --- a/src/bun.js/crypto.exports.js +++ b/src/bun.js/crypto.exports.js @@ -8456,38 +8456,10 @@ var require_brorand = __commonJS({ return this._rand(len); }; Rand.prototype._rand = function (n) { - if (this.rand.getBytes) return this.rand.getBytes(n); - for (var res = new Uint8Array(n), i = 0; i < res.length; i++) - res[i] = this.rand.getByte(); - return res; + var out = new Buffer(n); + crypto.getRandomValues(out); + return out; }; - if (typeof self == "object") - self.crypto && self.crypto.getRandomValues - ? (Rand.prototype._rand = function (n) { - var arr = new Uint8Array(n); - return self.crypto.getRandomValues(arr), arr; - }) - : self.msCrypto && self.msCrypto.getRandomValues - ? (Rand.prototype._rand = function (n) { - var arr = new Uint8Array(n); - return self.msCrypto.getRandomValues(arr), arr; - }) - : typeof window == "object" && - (Rand.prototype._rand = function () { - throw new Error("Not implemented yet"); - }); - else - try { - if ( - ((crypto2 = require_crypto_browserify()), - typeof crypto2.randomBytes != "function") - ) - throw new Error("Not supported"); - Rand.prototype._rand = function (n) { - return crypto2.randomBytes(n); - }; - } catch {} - var crypto2; }, }); |