summaryrefslogtreecommitdiffstats
path: root/node_modules/brorand/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/brorand/index.js')
-rw-r--r--node_modules/brorand/index.js65
1 files changed, 0 insertions, 65 deletions
diff --git a/node_modules/brorand/index.js b/node_modules/brorand/index.js
deleted file mode 100644
index 9a0fff4..0000000
--- a/node_modules/brorand/index.js
+++ /dev/null
@@ -1,65 +0,0 @@
-var r;
-
-module.exports = function rand(len) {
- if (!r)
- r = new Rand(null);
-
- return r.generate(len);
-};
-
-function Rand(rand) {
- this.rand = rand;
-}
-module.exports.Rand = Rand;
-
-Rand.prototype.generate = function generate(len) {
- return this._rand(len);
-};
-
-// Emulate crypto API using randy
-Rand.prototype._rand = function _rand(n) {
- if (this.rand.getBytes)
- return this.rand.getBytes(n);
-
- var res = new Uint8Array(n);
- for (var i = 0; i < res.length; i++)
- res[i] = this.rand.getByte();
- return res;
-};
-
-if (typeof self === 'object') {
- if (self.crypto && self.crypto.getRandomValues) {
- // Modern browsers
- Rand.prototype._rand = function _rand(n) {
- var arr = new Uint8Array(n);
- self.crypto.getRandomValues(arr);
- return arr;
- };
- } else if (self.msCrypto && self.msCrypto.getRandomValues) {
- // IE
- Rand.prototype._rand = function _rand(n) {
- var arr = new Uint8Array(n);
- self.msCrypto.getRandomValues(arr);
- return arr;
- };
-
- // Safari's WebWorkers do not have `crypto`
- } else if (typeof window === 'object') {
- // Old junk
- Rand.prototype._rand = function() {
- throw new Error('Not implemented yet');
- };
- }
-} else {
- // Node.js or Web worker with no crypto support
- try {
- var crypto = require('crypto');
- if (typeof crypto.randomBytes !== 'function')
- throw new Error('Not supported');
-
- Rand.prototype._rand = function _rand(n) {
- return crypto.randomBytes(n);
- };
- } catch (e) {
- }
-}