diff --git a/lib/secure-random-string.js b/lib/secure-random-string.js index 20810c7..6813a6a 100644 --- a/lib/secure-random-string.js +++ b/lib/secure-random-string.js @@ -12,15 +12,19 @@ function srs(options, cb) { crypto.randomBytes(length, function(ex, buf) { if (ex) throw ex; + cb(_finish(buf)); + }); + + function _finish (buf) { var string = buf.toString('base64'); if (options.urlsafe) { string = string.replace(/\//g,'_').replace(/\+/g,'-'); } - - cb(string.substr(0, length)); - }); + return string.substr(0, length); + } }; + module.exports = srs;