Browse files

Merge pull request #163 from shakkame/master-squash

support for domains
  • Loading branch information...
2 parents f5e6618 + 1769698 commit d1576b1b6dbaf6cc3546a94cec39c996b6c84a5d @defunctzombie defunctzombie committed Apr 29, 2013
Showing with 14 additions and 0 deletions.
  1. +14 −0 bcrypt.js
View
14 bcrypt.js
@@ -1,5 +1,13 @@
var bindings = require('bindings')('bcrypt_lib');
+var bind_to_domain = function(cb) {
+ if (process.domain) {
+ cb = process.domain.bind(cb);
+ }
+
+ return cb;
+}
+
/// generate a salt (sync)
/// @param {Number} [rounds] number of rounds (default 10)
/// @param {Number} [seed_length] number of random bytes (default 20)
@@ -70,6 +78,8 @@ module.exports.genSalt = function(rounds, seed_length, cb) {
throw new Error('callback required for gen_salt');
}
+ cb = bind_to_domain(cb);
+
return bindings.gen_salt(rounds, seed_length, cb);
};
@@ -126,6 +136,8 @@ module.exports.hash = function(data, salt, cb) {
});
}
+ cb = bind_to_domain(cb);
+
return bindings.encrypt(data, salt, cb);
};
@@ -166,6 +178,8 @@ module.exports.compare = function(data, hash, cb) {
throw new Error('callback must be a function');
}
+ cb = bind_to_domain(cb);
+
return bindings.compare(data, hash, cb);
};

0 comments on commit d1576b1

Please sign in to comment.