more
This commit is contained in:
dopeuni444
2025-07-31 12:23:33 +04:00
parent 20b46678b7
commit b5a22951ae
3401 changed files with 331100 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
sudo: 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"

View File

@@ -0,0 +1 @@
ui: tape

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
}

View File

@@ -0,0 +1,36 @@
{
"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"
}
}