Skip to content

Commit

Permalink
Merge pull request #163 from shakkame/master-squash
Browse files Browse the repository at this point in the history
support for domains
  • Loading branch information
defunctzombie committed Apr 29, 2013
2 parents f5e6618 + 1769698 commit d1576b1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 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)
Expand Down Expand Up @@ -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);
};

Expand Down Expand Up @@ -126,6 +136,8 @@ module.exports.hash = function(data, salt, cb) {
});
}

cb = bind_to_domain(cb);

return bindings.encrypt(data, salt, cb);
};

Expand Down Expand Up @@ -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);
};

Expand Down

0 comments on commit d1576b1

Please sign in to comment.