aboutsummaryrefslogtreecommitdiff
path: root/node_modules/randombytes
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/randombytes')
-rw-r--r--node_modules/randombytes/.travis.yml15
-rw-r--r--node_modules/randombytes/.zuul.yml1
-rw-r--r--node_modules/randombytes/README.md14
-rw-r--r--node_modules/randombytes/browser.js36
-rw-r--r--node_modules/randombytes/index.js1
-rw-r--r--node_modules/randombytes/package.json33
-rw-r--r--node_modules/randombytes/test.js56
7 files changed, 156 insertions, 0 deletions
diff --git a/node_modules/randombytes/.travis.yml b/node_modules/randombytes/.travis.yml
new file mode 100644
index 000000000..f8eebd870
--- /dev/null
+++ b/node_modules/randombytes/.travis.yml
@@ -0,0 +1,15 @@
+sudo: false
+language: node_js
+matrix:
+ include:
+ - node_js: '0.10'
+ env: TEST_SUITE=test
+ - node_js: '0.12'
+ env: TEST_SUITE=test
+ - node_js: '5'
+ env: TEST_SUITE=test
+ - node_js: '4'
+ env: TEST_SUITE=test
+ - node_js: '4'
+ env: TEST_SUITE=phantom
+script: "npm run-script $TEST_SUITE"
diff --git a/node_modules/randombytes/.zuul.yml b/node_modules/randombytes/.zuul.yml
new file mode 100644
index 000000000..96d9cfbd3
--- /dev/null
+++ b/node_modules/randombytes/.zuul.yml
@@ -0,0 +1 @@
+ui: tape
diff --git a/node_modules/randombytes/README.md b/node_modules/randombytes/README.md
new file mode 100644
index 000000000..3bacba4d1
--- /dev/null
+++ b/node_modules/randombytes/README.md
@@ -0,0 +1,14 @@
+randombytes
+===
+
+[![Version](http://img.shields.io/npm/v/randombytes.svg)](https://www.npmjs.org/package/randombytes) [![Build Status](https://travis-ci.org/crypto-browserify/randombytes.svg?branch=master)](https://travis-ci.org/crypto-browserify/randombytes)
+
+randombytes from node that works in the browser. In node you just get crypto.randomBytes, but in the browser it uses .crypto/msCrypto.getRandomValues
+
+```js
+var randomBytes = require('randombytes');
+randomBytes(16);//get 16 random bytes
+randomBytes(16, function (err, resp) {
+ // resp is 16 random bytes
+});
+```
diff --git a/node_modules/randombytes/browser.js b/node_modules/randombytes/browser.js
new file mode 100644
index 000000000..1aa3edcc7
--- /dev/null
+++ b/node_modules/randombytes/browser.js
@@ -0,0 +1,36 @@
+'use strict'
+
+function oldBrowser () {
+ throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11')
+}
+
+var crypto = global.crypto || global.msCrypto
+
+if (crypto && crypto.getRandomValues) {
+ module.exports = randomBytes
+} else {
+ module.exports = oldBrowser
+}
+
+function randomBytes (size, cb) {
+ // phantomjs needs to throw
+ if (size > 65536) throw new Error('requested too many random bytes')
+ // in case browserify isn't using the Uint8Array version
+ var rawBytes = new global.Uint8Array(size)
+
+ // This will not work in older browsers.
+ // See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
+ if (size > 0) { // getRandomValues fails on IE if size == 0
+ crypto.getRandomValues(rawBytes)
+ }
+ // phantomjs doesn't like a buffer being passed here
+ var bytes = new Buffer(rawBytes.buffer)
+
+ if (typeof cb === 'function') {
+ return process.nextTick(function () {
+ cb(null, bytes)
+ })
+ }
+
+ return bytes
+}
diff --git a/node_modules/randombytes/index.js b/node_modules/randombytes/index.js
new file mode 100644
index 000000000..a2d9e3911
--- /dev/null
+++ b/node_modules/randombytes/index.js
@@ -0,0 +1 @@
+module.exports = require('crypto').randomBytes
diff --git a/node_modules/randombytes/package.json b/node_modules/randombytes/package.json
new file mode 100644
index 000000000..0bd60318d
--- /dev/null
+++ b/node_modules/randombytes/package.json
@@ -0,0 +1,33 @@
+{
+ "name": "randombytes",
+ "version": "2.0.3",
+ "description": "random bytes from browserify stand alone",
+ "main": "index.js",
+ "scripts": {
+ "test": "standard && node test.js | tspec",
+ "phantom": "zuul --phantom -- test.js",
+ "local": "zuul --local --no-coverage -- test.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git@github.com:crypto-browserify/randombytes.git"
+ },
+ "keywords": [
+ "crypto",
+ "random"
+ ],
+ "author": "",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/crypto-browserify/randombytes/issues"
+ },
+ "homepage": "https://github.com/crypto-browserify/randombytes",
+ "browser": "browser.js",
+ "devDependencies": {
+ "phantomjs": "^1.9.9",
+ "standard": "^3.3.0",
+ "tap-spec": "^2.1.2",
+ "tape": "^3.0.3",
+ "zuul": "^3.7.2"
+ }
+}
diff --git a/node_modules/randombytes/test.js b/node_modules/randombytes/test.js
new file mode 100644
index 000000000..8e34dcaa4
--- /dev/null
+++ b/node_modules/randombytes/test.js
@@ -0,0 +1,56 @@
+var test = require('tape')
+var randomBytes = require('./')
+
+test('sync', function (t) {
+ t.plan(4)
+ t.equals(randomBytes(0).length, 0, 'len: ' + 0)
+ t.equals(randomBytes(3).length, 3, 'len: ' + 3)
+ t.equals(randomBytes(30).length, 30, 'len: ' + 30)
+ t.equals(randomBytes(300).length, 300, 'len: ' + 300)
+})
+
+test('async', function (t) {
+ t.plan(4)
+
+ randomBytes(0, function (err, resp) {
+ if (err) throw err
+
+ t.equals(resp.length, 0, 'len: ' + 0)
+ })
+
+ randomBytes(3, function (err, resp) {
+ if (err) throw err
+
+ t.equals(resp.length, 3, 'len: ' + 3)
+ })
+
+ randomBytes(30, function (err, resp) {
+ if (err) throw err
+
+ t.equals(resp.length, 30, 'len: ' + 30)
+ })
+
+ randomBytes(300, function (err, resp) {
+ if (err) throw err
+
+ t.equals(resp.length, 300, 'len: ' + 300)
+ })
+})
+
+if (process.browser) {
+ test('requesting to much throws', function (t) {
+ t.plan(1)
+ t.throws(function () {
+ randomBytes(65537)
+ })
+ })
+
+ test('requesting to much throws async', function (t) {
+ t.plan(1)
+ t.throws(function () {
+ randomBytes(65537, function () {
+ t.ok(false, 'should not get here')
+ })
+ })
+ })
+}