From bbff7403fbf46f9ad92240ac213df8d30ef31b64 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Sep 2018 02:56:13 +0200 Subject: update packages --- node_modules/pbkdf2/lib/async.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'node_modules/pbkdf2/lib/async.js') diff --git a/node_modules/pbkdf2/lib/async.js b/node_modules/pbkdf2/lib/async.js index c0b91b9a8..b20da7c8b 100644 --- a/node_modules/pbkdf2/lib/async.js +++ b/node_modules/pbkdf2/lib/async.js @@ -37,6 +37,7 @@ function checkNative (algo) { checks[algo] = prom return prom } + function browserPbkdf2 (password, salt, iterations, length, algo) { return subtle.importKey( 'raw', password, {name: 'PBKDF2'}, false, ['deriveBits'] @@ -53,6 +54,7 @@ function browserPbkdf2 (password, salt, iterations, length, algo) { return Buffer.from(res) }) } + function resolvePromise (promise, callback) { promise.then(function (out) { process.nextTick(function () { @@ -65,18 +67,14 @@ function resolvePromise (promise, callback) { }) } module.exports = function (password, salt, iterations, keylen, digest, callback) { - if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding) - if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding) - - checkParameters(iterations, keylen) if (typeof digest === 'function') { callback = digest digest = undefined } - if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2') digest = digest || 'sha1' var algo = toBrowser[digest.toLowerCase()] + if (!algo || typeof global.Promise !== 'function') { return process.nextTick(function () { var out @@ -88,11 +86,15 @@ module.exports = function (password, salt, iterations, keylen, digest, callback) callback(null, out) }) } + + checkParameters(password, salt, iterations, keylen) + if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2') + if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding) + if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding) + resolvePromise(checkNative(algo).then(function (resp) { - if (resp) { - return browserPbkdf2(password, salt, iterations, keylen, algo) - } else { - return sync(password, salt, iterations, keylen, digest) - } + if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo) + + return sync(password, salt, iterations, keylen, digest) }), callback) } -- cgit v1.2.3