aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar buttercat1791 <mjjurkoic@gmail.com>2024-05-20 20:02:23 -0500
committerLibravatar buttercat1791 <mjjurkoic@gmail.com>2024-05-20 20:02:23 -0500
commitc371b309fcce7a024cd83e08bbbf53971fcf1133 (patch)
tree2b42a916323dff89ae9223c9b9275b3ff04341a8
parent6c47d55f41143ecaac283edd7bb9dfba735e50bd (diff)
Correct noscrypt setup
-rw-r--r--include/signer/signer.hpp1
-rw-r--r--src/signer/noscrypt_signer.cpp37
2 files changed, 35 insertions, 3 deletions
diff --git a/include/signer/signer.hpp b/include/signer/signer.hpp
index 7dccc7c..22a71c6 100644
--- a/include/signer/signer.hpp
+++ b/include/signer/signer.hpp
@@ -4,6 +4,7 @@
#include <random>
#include <plog/Init.h>
+#include <plog/Log.h>
#include "data/data.hpp"
diff --git a/src/signer/noscrypt_signer.cpp b/src/signer/noscrypt_signer.cpp
index e53dd57..26f8e54 100644
--- a/src/signer/noscrypt_signer.cpp
+++ b/src/signer/noscrypt_signer.cpp
@@ -18,14 +18,16 @@ public:
// Set up the noscrypt library.
this->context = make_shared<NCContext>();
- uint8_t randomEntropy[NC_CONTEXT_ENTROPY_SIZE];
+ auto contextStructSize = NCGetContextStructSize();
+ unique_ptr<uint8_t[]> randomEntropy(new uint8_t[contextStructSize]);
random_device device;
mt19937 seed(device());
uniform_int_distribution<int> distribution(1, NC_CONTEXT_ENTROPY_SIZE);
- generate_n(randomEntropy, NC_CONTEXT_ENTROPY_SIZE, [&]() { return distribution(seed); });
+ generate_n(randomEntropy.get(), NC_CONTEXT_ENTROPY_SIZE, [&]() { return distribution(seed); });
- NCInitContext(context.get(), randomEntropy);
+ NCResult result = NCInitContext(context.get(), randomEntropy.get());
+ this->handleNoscryptInitResult(result);
};
~NoscryptSigner()
@@ -54,6 +56,35 @@ public:
private:
shared_ptr<NCContext> context;
+
+ void handleNoscryptInitResult(NCResult result)
+ {
+ switch (result) {
+ case NC_SUCCESS:
+ PLOG_INFO << "Successfully initialized noscrypt.";
+ break;
+
+ case E_NULL_PTR:
+ PLOG_ERROR << "Failed to initialize noscrypt: A null pointer was passed to the initializer.";
+ break;
+
+ case E_INVALID_ARG:
+ PLOG_ERROR << "Failed to initialize noscrypt: An invalid argument was passed to the initializer.";
+ break;
+
+ case E_INVALID_CONTEXT:
+ PLOG_ERROR << "Failed to initialize noscrypt: The NCContext struct is in an invalid state.";
+ break;
+
+ case E_ARGUMENT_OUT_OF_RANGE:
+ PLOG_ERROR << "Failed to initialize noscrypt: An initializer argument was outside the range of acceptable values.";
+ break;
+
+ case E_OPERATION_FAILED:
+ PLOG_ERROR << "Failed to initialize noscrypt.";
+ break;
+ }
+ };
};
} // namespace signer
} // namespace nostr