[Pkg-javascript-commits] [node-randombytes] 01/05: Import Upstream version 2.0.3

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Thu Oct 27 10:43:22 UTC 2016


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository node-randombytes.

commit 92c8f1a579b93151365053ab514d13678640bf79
Author: Sarath M S <debian at sarathms.me>
Date:   Thu Oct 27 13:44:27 2016 +0530

    Import Upstream version 2.0.3
---
 .travis.yml  | 15 +++++++++++++++
 .zuul.yml    |  1 +
 README.md    | 14 ++++++++++++++
 browser.js   | 36 ++++++++++++++++++++++++++++++++++++
 index.js     |  1 +
 package.json | 33 +++++++++++++++++++++++++++++++++
 test.js      | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 156 insertions(+)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..f8eebd8
--- /dev/null
+++ b/.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/.zuul.yml b/.zuul.yml
new file mode 100644
index 0000000..96d9cfb
--- /dev/null
+++ b/.zuul.yml
@@ -0,0 +1 @@
+ui: tape
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3bacba4
--- /dev/null
+++ b/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/browser.js b/browser.js
new file mode 100644
index 0000000..1aa3edc
--- /dev/null
+++ b/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/index.js b/index.js
new file mode 100644
index 0000000..a2d9e39
--- /dev/null
+++ b/index.js
@@ -0,0 +1 @@
+module.exports = require('crypto').randomBytes
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..0bd6031
--- /dev/null
+++ b/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 at 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/test.js b/test.js
new file mode 100644
index 0000000..8e34dca
--- /dev/null
+++ b/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')
+      })
+    })
+  })
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-randombytes.git



More information about the Pkg-javascript-commits mailing list