diff options
Diffstat (limited to 'deps/npm/node_modules/cryptiles/lib/index.js')
-rwxr-xr-x | deps/npm/node_modules/cryptiles/lib/index.js | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/deps/npm/node_modules/cryptiles/lib/index.js b/deps/npm/node_modules/cryptiles/lib/index.js index 511eab66d4..c8a046d743 100755 --- a/deps/npm/node_modules/cryptiles/lib/index.js +++ b/deps/npm/node_modules/cryptiles/lib/index.js @@ -1,50 +1,28 @@ -'use strict'; - // Load modules -const Crypto = require('crypto'); -const Boom = require('boom'); +var Crypto = require('crypto'); +var Boom = require('boom'); // Declare internals -const internals = {}; +var internals = {}; // Generate a cryptographically strong pseudo-random data exports.randomString = function (size) { - const buffer = exports.randomBits((size + 1) * 6); + var buffer = exports.randomBits((size + 1) * 6); if (buffer instanceof Error) { return buffer; } - const string = buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, ''); + var string = buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, ''); return string.slice(0, size); }; -// Return a random string of digits - -exports.randomDigits = function (size) { - - const buffer = exports.randomBits(size * 8); - if (buffer instanceof Error) { - return buffer; - } - - const digits = []; - for (let i = 0; i < buffer.length; ++i) { - digits.push(Math.floor(buffer[i] / 25.6)); - } - - return digits.join(''); -}; - - -// Generate a buffer of random bits - exports.randomBits = function (bits) { if (!bits || @@ -53,7 +31,7 @@ exports.randomBits = function (bits) { return Boom.internal('Invalid random bits count'); } - const bytes = Math.ceil(bits / 8); + var bytes = Math.ceil(bits / 8); try { return Crypto.randomBytes(bytes); } @@ -73,14 +51,14 @@ exports.fixedTimeComparison = function (a, b) { return false; } - let mismatch = (a.length === b.length ? 0 : 1); + var mismatch = (a.length === b.length ? 0 : 1); if (mismatch) { b = a; } - for (let i = 0; i < a.length; ++i) { - const ac = a.charCodeAt(i); - const bc = b.charCodeAt(i); + for (var i = 0, il = a.length; i < il; ++i) { + var ac = a.charCodeAt(i); + var bc = b.charCodeAt(i); mismatch |= (ac ^ bc); } |