Skip to content

Commit d7da20c

Browse files
committed
crypto: pbkdf2 throws when no callback provided
1 parent f362135 commit d7da20c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/crypto.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,19 @@ DiffieHellman.prototype.setPrivateKey = function(key, encoding) {
458458

459459

460460
exports.pbkdf2 = function(password, salt, iterations, keylen, callback) {
461+
if (typeof callback !== 'function')
462+
throw new Error('No callback provided to pbkdf2');
463+
464+
return pbkdf2(password, salt, iterations, keylen, callback);
465+
};
466+
467+
468+
exports.pbkdf2Sync = function(password, salt, iterations, keylen) {
469+
return pbkdf2(password, salt, iterations, keylen);
470+
};
471+
472+
473+
function pbkdf2(password, salt, iterations, keylen, callback) {
461474
password = toBuf(password);
462475
salt = toBuf(salt);
463476

@@ -476,11 +489,8 @@ exports.pbkdf2 = function(password, salt, iterations, keylen, callback) {
476489
var ret = binding.PBKDF2(password, salt, iterations, keylen);
477490
return ret.toString(encoding);
478491
}
479-
};
492+
}
480493

481-
exports.pbkdf2Sync = function(password, salt, iterations, keylen) {
482-
return exports.pbkdf2(password, salt, iterations, keylen);
483-
};
484494

485495

486496
exports.randomBytes = randomBytes;

test/simple/test-crypto-binary-default.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true);
657657
// Test PBKDF2 with RFC 6070 test vectors (except #4)
658658
//
659659
function testPBKDF2(password, salt, iterations, keylen, expected) {
660-
var actual = crypto.pbkdf2(password, salt, iterations, keylen);
660+
var actual = crypto.pbkdf2Sync(password, salt, iterations, keylen);
661661
assert.equal(actual, expected);
662662

663663
crypto.pbkdf2(password, salt, iterations, keylen, function(err, actual) {

0 commit comments

Comments
 (0)