aboutsummaryrefslogtreecommitdiff
path: root/node_modules/pbkdf2/lib
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
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/pbkdf2/lib')
-rw-r--r--node_modules/pbkdf2/lib/async.js22
-rw-r--r--node_modules/pbkdf2/lib/precondition.js12
-rw-r--r--node_modules/pbkdf2/lib/sync-browser.js4
-rw-r--r--node_modules/pbkdf2/lib/sync.js3
4 files changed, 27 insertions, 14 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)
}
diff --git a/node_modules/pbkdf2/lib/precondition.js b/node_modules/pbkdf2/lib/precondition.js
index 1519b0092..683db5630 100644
--- a/node_modules/pbkdf2/lib/precondition.js
+++ b/node_modules/pbkdf2/lib/precondition.js
@@ -1,5 +1,15 @@
var MAX_ALLOC = Math.pow(2, 30) - 1 // default in iojs
-module.exports = function (iterations, keylen) {
+
+function checkBuffer (buf, name) {
+ if (typeof buf !== 'string' && !Buffer.isBuffer(buf)) {
+ throw new TypeError(name + ' must be a buffer or string')
+ }
+}
+
+module.exports = function (password, salt, iterations, keylen) {
+ checkBuffer(password, 'Password')
+ checkBuffer(salt, 'Salt')
+
if (typeof iterations !== 'number') {
throw new TypeError('Iterations not a number')
}
diff --git a/node_modules/pbkdf2/lib/sync-browser.js b/node_modules/pbkdf2/lib/sync-browser.js
index 7f0bf9131..202d29edb 100644
--- a/node_modules/pbkdf2/lib/sync-browser.js
+++ b/node_modules/pbkdf2/lib/sync-browser.js
@@ -63,11 +63,11 @@ function getDigest (alg) {
}
function pbkdf2 (password, salt, iterations, keylen, digest) {
+ checkParameters(password, salt, iterations, keylen)
+
if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
- checkParameters(iterations, keylen)
-
digest = digest || 'sha1'
var hmac = new Hmac(digest, password, salt.length)
diff --git a/node_modules/pbkdf2/lib/sync.js b/node_modules/pbkdf2/lib/sync.js
index 67b2e543d..f691e31a6 100644
--- a/node_modules/pbkdf2/lib/sync.js
+++ b/node_modules/pbkdf2/lib/sync.js
@@ -15,10 +15,11 @@ var defaultEncoding = require('../lib/default-encoding')
var Buffer = require('safe-buffer').Buffer
function pbkdf2 (password, salt, iterations, keylen, digest) {
+ checkParameters(password, salt, iterations, keylen)
+
if (!Buffer.isBuffer(password)) password = Buffer.from(password, defaultEncoding)
if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, defaultEncoding)
- checkParameters(iterations, keylen)
digest = digest || 'sha1'
var DK = Buffer.allocUnsafe(keylen)