Skip to content

Commit

Permalink
Modernize and reformat with clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
ranisalt committed May 21, 2024
1 parent 853a021 commit da08baa
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions argon2_node.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "argon2/include/argon2.h"
#include <cassert>
#include <cstdint>
#include <napi.h>
#include <vector>
#include <string>

namespace {

Expand All @@ -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<argon2_type>(type)} {}

Napi::Promise GetPromise() { return deferred.Promise(); }
auto GetPromise() -> Napi::Promise { return deferred.Promise(); }

protected:
void Execute() override {
Expand All @@ -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 */
Expand Down Expand Up @@ -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<Napi::Object>();
auto worker = new HashWorker{info.Env(),
args["password"].As<Napi::Buffer<uint8_t>>(),
args["salt"].As<Napi::Buffer<uint8_t>>(),
args["secret"].As<Napi::Buffer<uint8_t>>(),
args["data"].As<Napi::Buffer<uint8_t>>(),
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<Napi::Buffer<uint8_t>>(),
args["salt"].As<Napi::Buffer<uint8_t>>(),
args["secret"].As<Napi::Buffer<uint8_t>>(),
args["data"].As<Napi::Buffer<uint8_t>>(),
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;
}
Expand Down

0 comments on commit da08baa

Please sign in to comment.