Comparing version 1.0.3 to 1.1.0
@@ -0,1 +1,7 @@ | ||
1.1.0 / 2015-02-01 | ||
================== | ||
* Use `crypto.randomBytes`, if available | ||
* deps: base64-url@1.2.1 | ||
1.0.3 / 2015-01-31 | ||
@@ -2,0 +8,0 @@ ================== |
29
index.js
@@ -14,3 +14,3 @@ /*! | ||
var Promise | ||
var pseudoRandomBytes = require('crypto').pseudoRandomBytes | ||
var crypto = require('crypto') | ||
var escape = require('base64-url').escape | ||
@@ -60,3 +60,7 @@ | ||
function uidSync(length) { | ||
return toString(pseudoRandomBytes(length)) | ||
try { | ||
return toString(crypto.randomBytes(length)) | ||
} catch (e) { | ||
return toString(crypto.pseudoRandomBytes(length)) | ||
} | ||
} | ||
@@ -73,3 +77,3 @@ | ||
function generateUid(length, callback) { | ||
pseudoRandomBytes(length, function (err, buf) { | ||
randomBytes(length, function (err, buf) { | ||
if (err) return callback(err) | ||
@@ -81,2 +85,21 @@ callback(null, toString(buf)) | ||
/** | ||
* Get some random bytes. | ||
* | ||
* @param {number} length | ||
* @param {function} callback | ||
* @return {Buffer} | ||
* @private | ||
*/ | ||
function randomBytes(length, callback) { | ||
crypto.randomBytes(length, function (err, buf) { | ||
if (!err) return callback(null, buf) | ||
crypto.pseudoRandomBytes(length, function (err, buf) { | ||
if (err) return callback(err) | ||
callback(null, buf) | ||
}) | ||
}) | ||
} | ||
/** | ||
* Change a Buffer into a string. | ||
@@ -83,0 +106,0 @@ * |
{ | ||
"name": "uid-safe", | ||
"description": "URL and cookie safe UIDs", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)", | ||
@@ -12,3 +12,3 @@ "contributors": [ | ||
"dependencies": { | ||
"base64-url": "1.2.0", | ||
"base64-url": "1.2.1", | ||
"native-or-bluebird": "~1.1.2" | ||
@@ -18,4 +18,5 @@ }, | ||
"bluebird": "2", | ||
"istanbul": "0", | ||
"mocha": "~2.1.0" | ||
"istanbul": "0.3.5", | ||
"mocha": "~2.1.0", | ||
"proxyquire": "~1.2.0" | ||
}, | ||
@@ -22,0 +23,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6689
93
4
+ Addedbase64-url@1.2.1(transitive)
- Removedbase64-url@1.2.0(transitive)
Updatedbase64-url@1.2.1