aboutsummaryrefslogtreecommitdiff
path: root/node_modules/pbkdf2/lib/async.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/pbkdf2/lib/async.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/pbkdf2/lib/async.js')
-rw-r--r--node_modules/pbkdf2/lib/async.js22
1 files changed, 12 insertions, 10 deletions
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)
}