Browse Source

crypto: pbkdf2 throws when no callback provided

v0.9.3-release
isaacs 12 years ago
parent
commit
d7da20c812
  1. 18
      lib/crypto.js
  2. 2
      test/simple/test-crypto-binary-default.js

18
lib/crypto.js

@ -458,6 +458,19 @@ DiffieHellman.prototype.setPrivateKey = function(key, encoding) {
exports.pbkdf2 = function(password, salt, iterations, keylen, callback) { 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); password = toBuf(password);
salt = toBuf(salt); salt = toBuf(salt);
@ -476,11 +489,8 @@ exports.pbkdf2 = function(password, salt, iterations, keylen, callback) {
var ret = binding.PBKDF2(password, salt, iterations, keylen); var ret = binding.PBKDF2(password, salt, iterations, keylen);
return ret.toString(encoding); return ret.toString(encoding);
} }
}; }
exports.pbkdf2Sync = function(password, salt, iterations, keylen) {
return exports.pbkdf2(password, salt, iterations, keylen);
};
exports.randomBytes = randomBytes; exports.randomBytes = randomBytes;

2
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) // Test PBKDF2 with RFC 6070 test vectors (except #4)
// //
function testPBKDF2(password, salt, iterations, keylen, expected) { 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); assert.equal(actual, expected);
crypto.pbkdf2(password, salt, iterations, keylen, function(err, actual) { crypto.pbkdf2(password, salt, iterations, keylen, function(err, actual) {

Loading…
Cancel
Save