[Pkg-javascript-commits] [node-randomfill] 01/47: first

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:52:50 UTC 2017


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

rouca pushed a commit to branch master
in repository node-randomfill.

commit fc3932a3df19e91ae51c141f45a675ed809b80dd
Author: Calvin Metcalf <cmetcalf at appgeo.com>
Date:   Thu Jan 15 09:17:47 2015 -0500

    first
---
 index.js       |  1 +
 package.json   | 28 ++++++++++++++++++++++++++++
 randomBytes.js | 23 +++++++++++++++++++++++
 test.js        |  9 +++++++++
 4 files changed, 61 insertions(+)

diff --git a/index.js b/index.js
new file mode 100644
index 0000000..ccdab3f
--- /dev/null
+++ b/index.js
@@ -0,0 +1 @@
+module.exports = require('crypto').randomBytes;
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..db033cc
--- /dev/null
+++ b/package.json
@@ -0,0 +1,28 @@
+{
+  "name": "randombytes",
+  "version": "1.0.0",
+  "description": "random bytes from browserify stand alone",
+  "main": "index.js",
+  "scripts": {
+    "test": "node test.js | tspec"
+  },
+  "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": "randomBytes.js",
+  "devDependencies": {
+    "tap-spec": "^2.1.2",
+    "tape": "^3.0.3"
+  }
+}
diff --git a/randomBytes.js b/randomBytes.js
new file mode 100644
index 0000000..de5f7b9
--- /dev/null
+++ b/randomBytes.js
@@ -0,0 +1,23 @@
+'use strict';
+
+var crypto = global.crypto || global.msCrypto
+if(crypto.getRandomValues) {
+  module.exports = randomBytes;
+} else {
+  module.exports = oldBrowser;
+}
+function randomBytes(size) {
+  var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array
+    /* This will not work in older browsers.
+     * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
+     */
+
+  crypto.getRandomValues(bytes);
+  return bytes;
+}
+function oldBrowser() {
+  throw new Error(
+      'secure random number generation not supported by this browser\n'+
+      'use chrome, FireFox or Internet Explorer 11'
+    )
+}
\ No newline at end of file
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..061f010
--- /dev/null
+++ b/test.js
@@ -0,0 +1,9 @@
+var test = require("tape");
+var randomBytes = require('./');
+
+test('correct length', function (t) {
+    t.plan(3);
+    t.equals(randomBytes(3).length, 3, 3);
+    t.equals(randomBytes(30).length, 30, 30);
+    t.equals(randomBytes(300).length, 300, 300);
+});
\ No newline at end of file

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



More information about the Pkg-javascript-commits mailing list