aboutsummaryrefslogtreecommitdiff
path: root/include/Hash.hpp
diff options
context:
space:
mode:
authorAleksi Lindeman <0xdec05eba@gmail.com>2018-03-05 22:45:56 +0100
committerAleksi Lindeman <0xdec05eba@gmail.com>2018-03-05 22:48:26 +0100
commit2ffb47d0043e57707474e5ae811f97c2e5e93f25 (patch)
treefd60b300cdf736de5adc68b395105dcfc6a43f09 /include/Hash.hpp
parent66661e47dc826f50b690e080057f47a0ea27016c (diff)
Implement 'create' operation, add seeding
Seeding is currently only done on the key you specify, in the future the user should request data that it can seed.
Diffstat (limited to 'include/Hash.hpp')
-rw-r--r--include/Hash.hpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/Hash.hpp b/include/Hash.hpp
new file mode 100644
index 0000000..d7c90b0
--- /dev/null
+++ b/include/Hash.hpp
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "utils.hpp"
+#include <sodium/crypto_generichash_blake2b.h>
+#include <stdexcept>
+#include <unordered_map>
+
+namespace odhtdb
+{
+ const int HASH_BYTE_SIZE = 32;
+
+ class HashException : public std::runtime_error
+ {
+ public:
+ HashException(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ };
+
+ class Hash
+ {
+ public:
+ Hash();
+ // Throws HashException on failure
+ Hash(const void *input, const size_t inputSize);
+
+ void* getData() const { return (void*)data; }
+ size_t getSize() const { return HASH_BYTE_SIZE; }
+
+ size_t operator()() const;
+ bool operator==(const Hash &other) const;
+
+ std::string toString() const;
+ private:
+ char data[HASH_BYTE_SIZE];
+ };
+
+ struct HashHasher
+ {
+ size_t operator()(const Hash &hash) const
+ {
+ return hash();
+ }
+ };
+
+ template <typename ValueType>
+ using MapHashKey = std::unordered_map<Hash, ValueType, HashHasher>;
+}