From d7da20c812c5842d134252c7b3cdbf20a7dab243 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 23 Oct 2012 10:29:06 -0700 Subject: [PATCH] crypto: pbkdf2 throws when no callback provided --- lib/crypto.js | 18 ++++++++++++++---- test/simple/test-crypto-binary-default.js | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/crypto.js b/lib/crypto.js index 7efa624..a787e09 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 535a578..85c5447 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) { -- 2.7.4