Skip to content

Commit 70c2fba

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

1 file changed

Lines changed: 4 additions & 19 deletions

File tree

src/bcrypt_node.cc

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +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-
}
212197

213198
/* SALT GENERATION */
214199
void GenSaltAsync(uv_work_t* req) {
@@ -242,7 +227,7 @@ void GenSaltAsyncAfter(uv_work_t* req) {
242227
}
243228
else {
244229
argv[0] = Undefined();
245-
argv[1] = EncodeBinary(baton->salt.c_str(), baton->salt.size());
230+
argv[1] = Encode(baton->salt.c_str(), baton->salt.size());
246231
}
247232

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

296-
return scope.Close(EncodeBinary(salt, strlen(salt)));
281+
return scope.Close(Encode(salt, strlen(salt)));
297282
}
298283

299284
/* ENCRYPT DATA - USED TO BE HASHPW */
@@ -323,7 +308,7 @@ void EncryptAsyncAfter(uv_work_t* req) {
323308
}
324309
else {
325310
argv[0] = Undefined();
326-
argv[1] = EncodeBinary(baton->output.c_str(), baton->output.size());
311+
argv[1] = Encode(baton->output.c_str(), baton->output.size());
327312
}
328313

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

368353
char bcrypted[_PASSWORD_LEN];
369354
bcrypt(*data, *salt, bcrypted);
370-
return scope.Close(EncodeBinary(bcrypted, strlen(bcrypted)));
355+
return scope.Close(Encode(bcrypted, strlen(bcrypted)));
371356
}
372357

373358
/* COMPARATOR */

0 commit comments

Comments
 (0)