1
|
var checkParameters = require('./lib/precondition')
|
2
|
var native = require('crypto')
|
3
|
|
4
|
function nativePBKDF2 (password, salt, iterations, keylen, digest, callback) {
|
5
|
checkParameters(password, salt, iterations, keylen)
|
6
|
|
7
|
if (typeof digest === 'function') {
|
8
|
callback = digest
|
9
|
digest = 'sha1'
|
10
|
}
|
11
|
if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2')
|
12
|
|
13
|
return native.pbkdf2(password, salt, iterations, keylen, digest, callback)
|
14
|
}
|
15
|
|
16
|
function nativePBKDF2Sync (password, salt, iterations, keylen, digest) {
|
17
|
checkParameters(password, salt, iterations, keylen)
|
18
|
digest = digest || 'sha1'
|
19
|
return native.pbkdf2Sync(password, salt, iterations, keylen, digest)
|
20
|
}
|
21
|
|
22
|
/* istanbul ignore next */
|
23
|
if (!native.pbkdf2Sync || native.pbkdf2Sync.toString().indexOf('keylen, digest') === -1) {
|
24
|
exports.pbkdf2Sync = require('./lib/sync')
|
25
|
exports.pbkdf2 = require('./lib/async')
|
26
|
|
27
|
// native
|
28
|
} else {
|
29
|
exports.pbkdf2Sync = nativePBKDF2Sync
|
30
|
exports.pbkdf2 = nativePBKDF2
|
31
|
}
|