From d75c23bdad85c022ac0e034a090ec5d0ef6c7af2 Mon Sep 17 00:00:00 2001 From: Ranieri Althoff Date: Sun, 21 Jan 2024 21:40:29 +0100 Subject: [PATCH] Remove Napi using-directive --- argon2_node.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/argon2_node.cpp b/argon2_node.cpp index 139c737..97d10eb 100644 --- a/argon2_node.cpp +++ b/argon2_node.cpp @@ -1,15 +1,13 @@ - #include "argon2/include/argon2.h" #include #include #include #include -using namespace Napi; using ustring = std::vector; -static ustring from_buffer(const Value &value) { - const auto &buf = value.As>(); +static ustring from_buffer(const Napi::Value &value) { + const auto &buf = value.As>(); const auto &data = buf.Data(); return {data, data + buf.Length()}; } @@ -53,14 +51,15 @@ static argon2_context make_context(uint8_t *buf, ustring &plain, ustring &salt, return ctx; } -class HashWorker final : public AsyncWorker { +class HashWorker final : public Napi::AsyncWorker { public: - HashWorker(const Env &env, ustring &&plain, ustring &&salt, Options &&opts) + HashWorker(const Napi::Env &env, ustring &&plain, ustring &&salt, + Options &&opts) : AsyncWorker{env, "argon2:HashWorker"}, deferred{env}, plain{std::move(plain)}, salt{std::move(salt)}, opts{std::move(opts)} {} - Promise GetPromise() { return deferred.Promise(); } + Napi::Promise GetPromise() { return deferred.Promise(); } protected: void Execute() override { @@ -78,13 +77,15 @@ class HashWorker final : public AsyncWorker { void OnOK() override { deferred.Resolve( - Buffer::Copy(Env(), hash.get(), opts.hash_length)); + Napi::Buffer::Copy(Env(), hash.get(), opts.hash_length)); } - void OnError(const Error &err) override { deferred.Reject(err.Value()); } + void OnError(const Napi::Error &err) override { + deferred.Reject(err.Value()); + } private: - Promise::Deferred deferred; + Napi::Promise::Deferred deferred; ustring plain; ustring salt; Options opts; @@ -92,7 +93,7 @@ class HashWorker final : public AsyncWorker { std::unique_ptr hash; }; -static Options extract_opts(const Object &opts) { +static Options extract_opts(const Napi::Object &opts) { return { opts.Has("secret") ? from_buffer(opts["secret"]) : ustring{}, opts.Has("associatedData") ? from_buffer(opts["associatedData"]) @@ -106,20 +107,20 @@ static Options extract_opts(const Object &opts) { }; } -static Value Hash(const CallbackInfo &info) { +static Napi::Value Hash(const Napi::CallbackInfo &info) { assert(info.Length() == 4 && info[0].IsBuffer() && info[1].IsBuffer() && info[2].IsObject()); auto worker = new HashWorker{info.Env(), from_buffer(info[0]), from_buffer(info[1]), - extract_opts(info[2].As())}; + extract_opts(info[2].As())}; worker->Queue(); return worker->GetPromise(); } -static Object init(Env env, Object exports) { - exports["hash"] = Function::New(env, Hash); +static Napi::Object init(Napi::Env env, Napi::Object exports) { + exports["hash"] = Napi::Function::New(env, Hash); return exports; }