mirror of
https://github.com/S2-/securerandomstring.git
synced 2025-08-02 18:30:04 +02:00
Add support for 'sync' API. Updates code, tests and docs.
This commit is contained in:
@@ -9,11 +9,17 @@ function srs(options, cb) {
|
||||
}
|
||||
var length = options['length'] || 32;
|
||||
|
||||
crypto.randomBytes(length, function(ex, buf) {
|
||||
if (ex) throw ex;
|
||||
|
||||
cb(_finish(buf));
|
||||
});
|
||||
// async path
|
||||
if (cb) {
|
||||
crypto.randomBytes(length, function(ex, buf) {
|
||||
if (ex) throw ex;
|
||||
return cb(_finish(buf));
|
||||
});
|
||||
}
|
||||
// sync path
|
||||
else {
|
||||
return _finish(crypto.randomBytes(length));
|
||||
}
|
||||
|
||||
function _finish (buf) {
|
||||
var string = buf.toString('base64');
|
||||
|
Reference in New Issue
Block a user