From bb4af5ff918dee0bcad84dd6c486d31d1582b9a7 Mon Sep 17 00:00:00 2001 From: Howard Engelhart Date: Mon, 24 Feb 2020 18:45:02 -0500 Subject: [PATCH 1/3] updated to use nan 2.14 --- package-lock.json | 13 +++++++++++++ package.json | 2 +- src/addon.cc | 13 ++++++++----- src/x509.cc | 21 +++++++++++---------- 4 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..309e58c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "x509", + "version": "0.3.4", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "nan": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" + } + } +} diff --git a/package.json b/package.json index cc6ee44..343ea01 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,6 @@ }, "license": "MIT", "dependencies": { - "nan": "2.12.0" + "nan": "2.14.0" } } diff --git a/src/addon.cc b/src/addon.cc index f0aab0c..0602fb5 100644 --- a/src/addon.cc +++ b/src/addon.cc @@ -7,26 +7,29 @@ using namespace v8; void init(Local exports) { + v8::Isolate* isolate = exports->GetIsolate(); + v8::Local context = isolate->GetCurrentContext(); + Nan::Set(exports, Nan::New("version").ToLocalChecked(), Nan::New(VERSION).ToLocalChecked()); Nan::Set(exports, Nan::New("verify").ToLocalChecked(), - Nan::New(verify)->GetFunction()); + Nan::New(verify)->GetFunction(context).ToLocalChecked()); Nan::Set(exports, Nan::New("getAltNames").ToLocalChecked(), - Nan::New(get_altnames)->GetFunction()); + Nan::New(get_altnames)->GetFunction(context).ToLocalChecked()); Nan::Set(exports, Nan::New("getSubject").ToLocalChecked(), - Nan::New(get_subject)->GetFunction()); + Nan::New(get_subject)->GetFunction(context).ToLocalChecked()); Nan::Set(exports, Nan::New("getIssuer").ToLocalChecked(), - Nan::New(get_issuer)->GetFunction()); + Nan::New(get_issuer)->GetFunction(context).ToLocalChecked()); Nan::Set(exports, Nan::New("parseCert").ToLocalChecked(), - Nan::New(parse_cert)->GetFunction()); + Nan::New(parse_cert)->GetFunction(context).ToLocalChecked()); } NODE_MODULE(x509, init) diff --git a/src/x509.cc b/src/x509.cc index 00e02ae..44ee132 100644 --- a/src/x509.cc +++ b/src/x509.cc @@ -37,13 +37,13 @@ std::string parse_args(const Nan::FunctionCallbackInfo& info) { Nan::ThrowTypeError("Certificate must be a string."); return std::string(); } - - if (info[0]->ToString()->Length() == 0) { + std::string val = *Nan::Utf8String(info[0]); + if (val.length() == 0) { Nan::ThrowTypeError("Certificate argument provided, but left blank."); return std::string(); } - return *Nan::Utf8String(info[0]->ToString()); + return val; } @@ -52,8 +52,8 @@ NAN_METHOD(verify) { Nan::HandleScope scope; OpenSSL_add_all_algorithms(); - std::string cert_path = *String::Utf8Value(info[0]->ToString()); - std::string ca_bundlestr = *String::Utf8Value(info[1]->ToString()); + std::string cert_path = *Nan::Utf8String(info[0]); + std::string ca_bundlestr = *Nan::Utf8String(info[1]); X509_STORE *store = NULL; X509_STORE_CTX *verify_ctx = NULL; @@ -115,7 +115,7 @@ NAN_METHOD(get_altnames) { if(parsed_arg.size() == 0) { info.GetReturnValue().SetUndefined(); } - Local exports(try_parse(parsed_arg)->ToObject()); + Local exports(try_parse(parsed_arg)->ToObject(Nan::GetCurrentContext()).ToLocalChecked()); Local key = Nan::New("altNames").ToLocalChecked(); info.GetReturnValue().Set( Nan::Get(exports, key).ToLocalChecked()); @@ -128,7 +128,7 @@ NAN_METHOD(get_subject) { if(parsed_arg.size() == 0) { info.GetReturnValue().SetUndefined(); } - Local exports(try_parse(parsed_arg)->ToObject()); + Local exports(try_parse(parsed_arg)->ToObject(Nan::GetCurrentContext()).ToLocalChecked()); Local key = Nan::New("subject").ToLocalChecked(); info.GetReturnValue().Set( Nan::Get(exports, key).ToLocalChecked()); @@ -141,7 +141,7 @@ NAN_METHOD(get_issuer) { if(parsed_arg.size() == 0) { info.GetReturnValue().SetUndefined(); } - Local exports(try_parse(parsed_arg)->ToObject()); + Local exports(try_parse(parsed_arg)->ToObject(Nan::GetCurrentContext()).ToLocalChecked()); Local key = Nan::New("issuer").ToLocalChecked(); info.GetReturnValue().Set( Nan::Get(exports, key).ToLocalChecked()); @@ -154,7 +154,7 @@ NAN_METHOD(parse_cert) { if(parsed_arg.size() == 0) { info.GetReturnValue().SetUndefined(); } - Local exports(try_parse(parsed_arg)->ToObject()); + Local exports(try_parse(parsed_arg)->ToObject(Nan::GetCurrentContext()).ToLocalChecked()); info.GetReturnValue().Set(exports); ERR_clear_error(); } @@ -459,7 +459,8 @@ Local parse_date(ASN1_TIME *date) { Local global = Nan::GetCurrentContext()->Global(); Local DateObject = Nan::Get(global, - Nan::New("Date").ToLocalChecked()).ToLocalChecked()->ToObject(); + Nan::New("Date").ToLocalChecked()).ToLocalChecked() + ->ToObject(Nan::GetCurrentContext()).ToLocalChecked(); return scope.Escape(Nan::CallAsConstructor(DateObject, 1, args).ToLocalChecked()); } From f99404637b8115dc160b1d04b9503e6f37fc5611 Mon Sep 17 00:00:00 2001 From: Howard Engelhart Date: Tue, 25 Feb 2020 05:28:53 -0500 Subject: [PATCH 2/3] simplified addon --- src/addon.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/addon.cc b/src/addon.cc index 0602fb5..a9da123 100644 --- a/src/addon.cc +++ b/src/addon.cc @@ -7,29 +7,26 @@ using namespace v8; void init(Local exports) { - v8::Isolate* isolate = exports->GetIsolate(); - v8::Local context = isolate->GetCurrentContext(); - Nan::Set(exports, Nan::New("version").ToLocalChecked(), Nan::New(VERSION).ToLocalChecked()); Nan::Set(exports, Nan::New("verify").ToLocalChecked(), - Nan::New(verify)->GetFunction(context).ToLocalChecked()); + Nan::New(verify)->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); Nan::Set(exports, Nan::New("getAltNames").ToLocalChecked(), - Nan::New(get_altnames)->GetFunction(context).ToLocalChecked()); + Nan::New(get_altnames)->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); Nan::Set(exports, Nan::New("getSubject").ToLocalChecked(), - Nan::New(get_subject)->GetFunction(context).ToLocalChecked()); + Nan::New(get_subject)->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); Nan::Set(exports, Nan::New("getIssuer").ToLocalChecked(), - Nan::New(get_issuer)->GetFunction(context).ToLocalChecked()); + Nan::New(get_issuer)->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); Nan::Set(exports, Nan::New("parseCert").ToLocalChecked(), - Nan::New(parse_cert)->GetFunction(context).ToLocalChecked()); + Nan::New(parse_cert)->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); } NODE_MODULE(x509, init) From 9325bcdadafe2dd2bd710a092ffc1761139bdd55 Mon Sep 17 00:00:00 2001 From: Howard Engelhart Date: Tue, 25 Feb 2020 05:31:40 -0500 Subject: [PATCH 3/3] removed really old versions of node travis config --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c45c402..cb4c789 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,13 +12,11 @@ language: node_js node_js: - "stable" - "4.0" - - "0.12" - - "0.10" install: - export CXX=g++-4.8 - $CXX --version - - npm i + - npm i before_install: - npm install -g node-gyp