diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-03-05 22:45:56 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | eda9a7bbefc5587bf1ff895a9214f450e64575fa (patch) | |
tree | 0f968fb7373a29cf116b4b6d473a966e28e62825 /include/Hash.hpp | |
parent | 33e823ddddddd4a13b1a05b90ae5b419b89bcb1d (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.hpp | 46 |
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>; +} |