Beta 7 with some repo names changed.

This commit is contained in:
Luis Fernando Molina committed 2020-11-15 13:05:19 +01:00
1 parent 0f7b40cca7
commit 963c19493a
3408 files changed
+462217 -15516

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
'use strict'
// limit of Crypto.getRandomValues()
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
var MAX_BYTES = 65536
// Node supports requesting up to this number of bytes
// https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48
var MAX_UINT32 = 4294967295
function oldBrowser () {
throw new Error('Secure random number generation is 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 > MAX_UINT32) throw new RangeError('requested too many random bytes')
var bytes = Buffer.allocUnsafe(size)
if (size > 0) { // getRandomValues fails on IE if size == 0
if (size > MAX_BYTES) { // this is the max bytes crypto.getRandomValues
// can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
for (var generated = 0; generated < size; generated += MAX_BYTES) {
// buffer.slice automatically checks if the end is past the end of
// the buffer so we don't have to here
crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES))
}
} else {
crypto.getRandomValues(bytes)
}
}
if (typeof cb === 'function') {
return process.nextTick(function () {
cb(null, bytes)
})
}
return bytes
}
+1
View File
@@ -0,0 +1 @@
module.exports = require('crypto').randomBytes
+40
View File
@@ -0,0 +1,40 @@
{
"name": "randombytes",
"version": "2.1.0",
"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"
}
,"_resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz"
,"_integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ=="
,"_from": "randombytes@^2.1.0"
}
+81
View File
@@ -0,0 +1,81 @@
var test = require('tape')
var randomBytes = require('./')
var MAX_BYTES = 65536
var MAX_UINT32 = 4294967295
test('sync', function (t) {
t.plan(9)
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)
t.equals(randomBytes(17 + MAX_BYTES).length, 17 + MAX_BYTES, 'len: ' + 17 + MAX_BYTES)
t.equals(randomBytes(MAX_BYTES * 100).length, MAX_BYTES * 100, 'len: ' + MAX_BYTES * 100)
t.throws(function () {
randomBytes(MAX_UINT32 + 1)
})
t.throws(function () {
t.equals(randomBytes(-1))
})
t.throws(function () {
t.equals(randomBytes('hello'))
})
})
test('async', function (t) {
t.plan(9)
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)
})
randomBytes(17 + MAX_BYTES, function (err, resp) {
if (err) throw err
t.equals(resp.length, 17 + MAX_BYTES, 'len: ' + 17 + MAX_BYTES)
})
randomBytes(MAX_BYTES * 100, function (err, resp) {
if (err) throw err
t.equals(resp.length, MAX_BYTES * 100, 'len: ' + MAX_BYTES * 100)
})
t.throws(function () {
randomBytes(MAX_UINT32 + 1, function () {
t.ok(false, 'should not get here')
})
})
t.throws(function () {
randomBytes(-1, function () {
t.ok(false, 'should not get here')
})
})
t.throws(function () {
randomBytes('hello', function () {
t.ok(false, 'should not get here')
})
})
})