Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
language: node_js
node_js:
- 4
- "0.12"
- "0.10"
- 6
- 8
- 10
- 12
- 13.6.0
addons:
apt:
sources:
Expand Down
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{
"target_name": "crypt3async",
"sources": [ "crypt3async.cc" ],
"include_dirs" : [ "<!(node -e \"require('nan')\")" ],
"conditions": [
['OS!="mac"', {
'link_settings': { "libraries": [ "-lcrypt" ] }
Expand Down
14 changes: 9 additions & 5 deletions crypt3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ NAN_METHOD(Method) {
return Nan::ThrowTypeError("Wrong arguments");
}

v8::String::Utf8Value key(info[0]->ToString());
v8::String::Utf8Value salt(info[1]->ToString());
Nan::Utf8String key(info[0]);
Nan::Utf8String salt(info[1]);

char* res = crypt(*key, *salt);
if (res != NULL) {
Expand All @@ -29,9 +29,13 @@ NAN_METHOD(Method) {
}
}

void init(Handle<Object> exports) {
exports->Set(Nan::New<String>("crypt").ToLocalChecked(),
Nan::New<FunctionTemplate>(Method)->GetFunction());

void init(Local<Object> exports) {
Nan::Set(
exports,
Nan::New<String>("crypt").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(Method)).ToLocalChecked()
);
}

NODE_MODULE(crypt3, init)
Expand Down
23 changes: 14 additions & 9 deletions crypt3async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Tested in node.js v4.4.2 LTS in Ubuntu Linux
*/

#include <nan.h>
#include <node.h>
#include <uv.h>
#include <iostream>
Expand Down Expand Up @@ -67,22 +68,26 @@ namespace asyncAddon {
*/
static void WorkAsyncComplete(uv_work_t *req,int status) {
Isolate * isolate = Isolate::GetCurrent();
v8::HandleScope handleScope(isolate);
v8::HandleScope handle_scope(isolate);
Work *work = static_cast<Work *>(req->data);
Local<v8::Context> context = isolate -> GetCurrentContext() ;
Local<Value> recv = Undefined( isolate ) ;


const int error = work->error;
const char *result = work->result.c_str();

if(error == 0) {
Local<Value> argv[2] = {
Undefined(isolate),
String::NewFromUtf8(isolate, result)
String::NewFromUtf8(isolate, result, v8::NewStringType::kNormal).ToLocalChecked()
};
// https://stackoverflow.com/questions/13826803/calling-javascript-function-from-a-c-callback-in-v8/28554065#28554065
Local<Function>::New(isolate, work->callback)->Call(isolate->GetCurrentContext()->Global(), 2, argv);
Local<Function>::New(isolate, work->callback)->Call(context, recv, 2, argv);
} else {
Local<Value> argv[1] = { String::NewFromUtf8(isolate, result) };
Local<Value> argv[1] = { String::NewFromUtf8(isolate, result, v8::NewStringType::kNormal).ToLocalChecked() };
// https://stackoverflow.com/questions/13826803/calling-javascript-function-from-a-c-callback-in-v8/28554065#28554065
Local<Function>::New(isolate, work->callback)->Call(isolate->GetCurrentContext()->Global(), 1, argv);
Local<Function>::New(isolate, work->callback)->Call(context, recv, 1, argv);
}

work->callback.Reset();
Expand All @@ -99,20 +104,20 @@ namespace asyncAddon {
work->request.data = work;

if (args.Length() < 3) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments")));
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong number of arguments", v8::NewStringType::kNormal).ToLocalChecked()));
return;
}

if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsFunction() ) {
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments")));
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments", v8::NewStringType::kNormal).ToLocalChecked()));
return;
}

v8::String::Utf8Value v8key(args[0]->ToString());
Nan::Utf8String v8key(args[0]);
string key = std::string(*v8key);
work->key = key;

v8::String::Utf8Value v8salt(args[1]->ToString());
Nan::Utf8String v8salt(args[1]);
string salt = std::string(*v8salt);
work->salt = salt;

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crypt3",
"version": "1.0.0",
"version": "1.1.0",
"description": "Node.js crypt(3) bindings",
"main": "src/index.js",
"scripts": {
Expand All @@ -9,7 +9,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/sendanor/node-crypt3.git"
"url": "https://github.com/ahmedbodi/node-crypt3.git"
},
"keywords": [
"crypt",
Expand All @@ -21,12 +21,13 @@
"hash"
],
"dependencies": {
"nan": "^2.1.0"
"nan": "^2.14.0"
},
"optionalDependencies": {
"q": "^1.0.1"
},
"author": "Jaakko-Heikki Heusala <jheusala@iki.fi>",
"maintainer": "Ahmed Bodiwala <ahmedbodi@crypto-expert.com>",
"license": "MIT",
"gypfile": true
}