diff --git a/argon2_node.cpp b/argon2_node.cpp index 4adc759..9010879 100644 --- a/argon2_node.cpp +++ b/argon2_node.cpp @@ -1,8 +1,7 @@ #include "argon2/include/argon2.h" -#include #include #include -#include +#include namespace { @@ -15,15 +14,15 @@ class HashWorker final : public Napi::AsyncWorker { uint32_t memory_cost, uint32_t time_cost, uint32_t parallelism, uint32_t version, uint32_t type) : AsyncWorker{env, "argon2:HashWorker"}, deferred{env}, - plain{plain.Data(), plain.Data() + plain.ByteLength()}, - salt{salt.Data(), salt.Data() + salt.ByteLength()}, - secret{secret.Data(), secret.Data() + secret.ByteLength()}, - ad{ad.Data(), ad.Data() + ad.ByteLength()}, hash_length{hash_length}, + plain{plain.Data(), plain.ByteLength()}, + salt{salt.Data(), salt.ByteLength()}, + secret{secret.Data(), secret.ByteLength()}, + ad{ad.Data(), ad.ByteLength()}, hash_length{hash_length}, memory_cost{memory_cost}, time_cost{time_cost}, parallelism{parallelism}, version{version}, type{static_cast(type)} {} - Napi::Promise GetPromise() { return deferred.Promise(); } + auto GetPromise() -> Napi::Promise { return deferred.Promise(); } protected: void Execute() override { @@ -49,7 +48,7 @@ class HashWorker final : public Napi::AsyncWorker { ctx.flags = ARGON2_FLAG_CLEAR_PASSWORD | ARGON2_FLAG_CLEAR_SECRET; ctx.version = version; - if (int result = argon2_ctx(&ctx, type); result != ARGON2_OK) { + if (const int result = argon2_ctx(&ctx, type); result != ARGON2_OK) { /* LCOV_EXCL_START */ SetError(argon2_error_message(result)); /* LCOV_EXCL_STOP */ @@ -85,27 +84,27 @@ class HashWorker final : public Napi::AsyncWorker { argon2_type type; }; -static Napi::Value Hash(const Napi::CallbackInfo &info) { +auto Hash(const Napi::CallbackInfo &info) -> Napi::Value { NAPI_CHECK(info.Length() == 1, "Hash", "expected 1 argument"); const auto &args = info[0].As(); - auto worker = new HashWorker{info.Env(), - args["password"].As>(), - args["salt"].As>(), - args["secret"].As>(), - args["data"].As>(), - args["hashLength"].ToNumber(), - args["m"].ToNumber(), - args["t"].ToNumber(), - args["p"].ToNumber(), - args["version"].ToNumber(), - args["type"].ToNumber()}; + auto *worker = new HashWorker{info.Env(), + args["password"].As>(), + args["salt"].As>(), + args["secret"].As>(), + args["data"].As>(), + args["hashLength"].ToNumber(), + args["m"].ToNumber(), + args["t"].ToNumber(), + args["p"].ToNumber(), + args["version"].ToNumber(), + args["type"].ToNumber()}; worker->Queue(); return worker->GetPromise(); } -static Napi::Object init(Napi::Env env, Napi::Object exports) { +auto init(Napi::Env env, Napi::Object exports) -> Napi::Object { exports["hash"] = Napi::Function::New(env, Hash); return exports; }