pax_global_header00006660000000000000000000000064131160521030014502gustar00rootroot0000000000000052 comment=9b470ac1419e5545a5265238ccc5db8a7f1f8644 randombytes-2.0.5/000077500000000000000000000000001311605210300140355ustar00rootroot00000000000000randombytes-2.0.5/.gitignore000066400000000000000000000000151311605210300160210ustar00rootroot00000000000000node_modules randombytes-2.0.5/.travis.yml000066400000000000000000000004771311605210300161560ustar00rootroot00000000000000sudo: false language: node_js matrix: include: - node_js: '7' env: TEST_SUITE=test - node_js: '6' 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" randombytes-2.0.5/.zuul.yml000066400000000000000000000000111311605210300156250ustar00rootroot00000000000000ui: tape randombytes-2.0.5/LICENSE000066400000000000000000000020621311605210300150420ustar00rootroot00000000000000MIT License Copyright (c) 2017 crypto-browserify Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. randombytes-2.0.5/README.md000066400000000000000000000010771311605210300153210ustar00rootroot00000000000000randombytes === [![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 }); ``` randombytes-2.0.5/browser.js000066400000000000000000000020711311605210300160560ustar00rootroot00000000000000'use strict' function oldBrowser () { throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11') } var Buffer = require('safe-buffer').Buffer 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) } // XXX: phantomjs doesn't like a buffer being passed here var bytes = Buffer.from(rawBytes.buffer) if (typeof cb === 'function') { return process.nextTick(function () { cb(null, bytes) }) } return bytes } randombytes-2.0.5/index.js000066400000000000000000000000571311605210300155040ustar00rootroot00000000000000module.exports = require('crypto').randomBytes randombytes-2.0.5/package.json000066400000000000000000000015451311605210300163300ustar00rootroot00000000000000{ "name": "randombytes", "version": "2.0.5", "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": "^10.0.2", "tap-spec": "^2.1.2", "tape": "^4.6.3", "zuul": "^3.7.2" }, "dependencies": { "safe-buffer": "^5.1.0" } } randombytes-2.0.5/test.js000066400000000000000000000022231311605210300153510ustar00rootroot00000000000000var 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') }) }) }) }