diff --git a/lib/crypto.js b/lib/crypto.js index 7efa6243f98..a787e09c348 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -458,6 +458,19 @@ DiffieHellman.prototype.setPrivateKey = function(key, encoding) { exports.pbkdf2 = function(password, salt, iterations, keylen, callback) { + if (typeof callback !== 'function') + throw new Error('No callback provided to pbkdf2'); + + return pbkdf2(password, salt, iterations, keylen, callback); +}; + + +exports.pbkdf2Sync = function(password, salt, iterations, keylen) { + return pbkdf2(password, salt, iterations, keylen); +}; + + +function pbkdf2(password, salt, iterations, keylen, callback) { password = toBuf(password); salt = toBuf(salt); @@ -476,11 +489,8 @@ exports.pbkdf2 = function(password, salt, iterations, keylen, callback) { var ret = binding.PBKDF2(password, salt, iterations, keylen); return ret.toString(encoding); } -}; +} -exports.pbkdf2Sync = function(password, salt, iterations, keylen) { - return exports.pbkdf2(password, salt, iterations, keylen); -}; exports.randomBytes = randomBytes; diff --git a/test/simple/test-crypto-binary-default.js b/test/simple/test-crypto-binary-default.js index 535a578a3bf..85c5447a2b1 100644 --- a/test/simple/test-crypto-binary-default.js +++ b/test/simple/test-crypto-binary-default.js @@ -657,7 +657,7 @@ assert.strictEqual(rsaVerify.verify(rsaPubPem, rsaSignature, 'hex'), true); // Test PBKDF2 with RFC 6070 test vectors (except #4) // function testPBKDF2(password, salt, iterations, keylen, expected) { - var actual = crypto.pbkdf2(password, salt, iterations, keylen); + var actual = crypto.pbkdf2Sync(password, salt, iterations, keylen); assert.equal(actual, expected); crypto.pbkdf2(password, salt, iterations, keylen, function(err, actual) {