Skip to content

Commit 55d3dd8

Browse files
committed
remove EncodeBinary in favor of node::Encode
this was made linkable with nodejs v0.8.5
1 parent dbada15 commit 55d3dd8

1 file changed

Lines changed: 5 additions & 21 deletions

File tree

src/bcrypt_node.cc

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,6 @@ bool ValidateSalt(const char* salt) {
194194
return true;
195195
}
196196

197-
Local<Value> EncodeBinary(const void *buf, size_t len) {
198-
HandleScope scope;
199-
200-
if (!len) return scope.Close(String::Empty());
201-
202-
const unsigned char *cbuf = static_cast<const unsigned char*>(buf);
203-
uint16_t * twobytebuf = new uint16_t[len];
204-
for (size_t i = 0; i < len; i++) {
205-
// XXX is the following line platform independent?
206-
twobytebuf[i] = cbuf[i];
207-
}
208-
Local<String> chunk = String::New(twobytebuf, len);
209-
delete [] twobytebuf; // TODO use ExternalTwoByteString?
210-
return scope.Close(chunk);
211-
}
212-
213197
/* SALT GENERATION */
214198
void GenSaltAsync(uv_work_t* req) {
215199

@@ -242,7 +226,7 @@ void GenSaltAsyncAfter(uv_work_t* req) {
242226
}
243227
else {
244228
argv[0] = Undefined();
245-
argv[1] = EncodeBinary(baton->salt.c_str(), baton->salt.size());
229+
argv[1] = Encode(baton->salt.c_str(), baton->salt.size(), BINARY);
246230
}
247231

248232
TryCatch try_catch; // don't quite see the necessity of this
@@ -293,7 +277,7 @@ Handle<Value> GenerateSaltSync(const Arguments& args) {
293277
char salt[_SALT_LEN];
294278
bcrypt_gensalt(rounds, seed.get(), salt);
295279

296-
return scope.Close(EncodeBinary(salt, strlen(salt)));
280+
return scope.Close(Encode(salt, strlen(salt), BINARY));
297281
}
298282

299283
/* ENCRYPT DATA - USED TO BE HASHPW */
@@ -323,7 +307,7 @@ void EncryptAsyncAfter(uv_work_t* req) {
323307
}
324308
else {
325309
argv[0] = Undefined();
326-
argv[1] = EncodeBinary(baton->output.c_str(), baton->output.size());
310+
argv[1] = Encode(baton->output.c_str(), baton->output.size(), BINARY);
327311
}
328312

329313
TryCatch try_catch; // don't quite see the necessity of this
@@ -367,7 +351,7 @@ Handle<Value> EncryptSync(const Arguments& args) {
367351

368352
char bcrypted[_PASSWORD_LEN];
369353
bcrypt(*data, *salt, bcrypted);
370-
return scope.Close(EncodeBinary(bcrypted, strlen(bcrypted)));
354+
return scope.Close(Encode(bcrypted, strlen(bcrypted), BINARY));
371355
}
372356

373357
/* COMPARATOR */
@@ -491,4 +475,4 @@ extern "C" void init(Handle<Object> target) {
491475
NODE_SET_METHOD(target, "compare", Compare);
492476
};
493477

494-
NODE_MODULE(bcrypt_lib, init);
478+
NODE_MODULE(bcrypt_lib, init);

0 commit comments

Comments
 (0)