Skip to content

Commit 20196db

Browse files
Calvin Metcalfcalvinmetcalf
authored andcommitted
pull out random bytes
1 parent 4b9dcfe commit 20196db

File tree

4 files changed

+7
-46
lines changed

4 files changed

+7
-46
lines changed

index.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
var rng = exports.rng = require('./rng')
2+
exports.randomBytes = exports.rng = require('randombytes')
33
var prng = exports.prng = require('./prng');
44

55
function error () {
@@ -15,19 +15,6 @@ exports.createHash = exports.Hash = require('create-hash')
1515

1616
exports.createHmac = exports.Hmac = require('create-hmac')
1717

18-
exports.randomBytes = function(size, callback) {
19-
if (callback && callback.call) {
20-
var res;
21-
try {
22-
res = rng(size)
23-
} catch (err) {
24-
return callback(err)
25-
}
26-
callback.call(this, undefined, res)
27-
} else {
28-
return rng(size)
29-
}
30-
}
3118
exports.pseudoRandomBytes = function(size, callback) {
3219
if (callback && callback.call) {
3320
var res;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"diffie-hellman": "2.2.3",
2525
"inherits": "^2.0.1",
2626
"pbkdf2-compat": "2.0.1",
27-
"public-encrypt": "1.1.2"
27+
"public-encrypt": "1.1.2",
28+
"randombytes": "^2.0.0"
2829
},
2930
"devDependencies": {
3031
"tape": "~2.3.2",

rng.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/random-bytes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
var test = require('tape')
22
var crypto = require('../')
3-
4-
var randomBytesFunctions = ['randomBytes', 'pseudoRandomBytes'];
3+
var randomBytes = require('randombytes')
4+
var randomBytesFunctions = [['randomBytes',randomBytes], ['pseudoRandomBytes', crypto.pseudoRandomBytes]];
55
for (var idx in randomBytesFunctions) {
66
// Both randomBytes and pseudoRandomBytes should provide the same interface
7-
var randomBytesName = randomBytesFunctions[idx];
8-
var randomBytes = crypto[randomBytesName]
7+
var randomBytesName = randomBytesFunctions[idx][0];
8+
var randomBytes = randomBytesFunctions[idx][1];
99
test('get error message', function (t) {
1010

1111
try {

0 commit comments

Comments
 (0)