aboutsummaryrefslogtreecommitdiff
path: root/include/Signature.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-03-13 06:26:06 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit5a8727e34b938b70623ca865273fd81c7604b461 (patch)
treea2921e90aa454072dc58fced36b508f67f5d1226 /include/Signature.hpp
parent9ffc25c9d99fe86d4789108d1d8615ecb0388cc6 (diff)
Expose include dir
Diffstat (limited to 'include/Signature.hpp')
-rw-r--r--include/Signature.hpp126
1 files changed, 0 insertions, 126 deletions
diff --git a/include/Signature.hpp b/include/Signature.hpp
deleted file mode 100644
index 62c41c3..0000000
--- a/include/Signature.hpp
+++ /dev/null
@@ -1,126 +0,0 @@
-#pragma once
-
-#include "DataView.hpp"
-#include <stdexcept>
-#include <unordered_map>
-
-namespace odhtdb
-{
- const int PUBLIC_KEY_NUM_BYTES = 32;
- const int PRIVATE_KEY_NUM_BYTES = 64;
- const int SIGNED_HASH_SIZE = 64;
-
- class InvalidSignatureKeySize : public std::runtime_error
- {
- public:
- InvalidSignatureKeySize(const std::string &errMsg) : std::runtime_error(errMsg) {}
- };
-
- class SignatureGenerationException : public std::runtime_error
- {
- public:
- SignatureGenerationException(const std::string &errMsg) : std::runtime_error(errMsg) {}
- };
-
- class DataSignException : public std::runtime_error
- {
- public:
- DataSignException(const std::string &errMsg) : std::runtime_error(errMsg) {}
- };
-
- class UnsignException : public std::runtime_error
- {
- public:
- UnsignException(const std::string &errMsg) : std::runtime_error(errMsg) {}
- virtual ~UnsignException(){}
- };
-
- class UnsignInvalidSizeException : public UnsignException
- {
- public:
- UnsignInvalidSizeException(const std::string &errMsg) : UnsignException(errMsg) {}
- };
-
- class UnsignWrongKeyException : public UnsignException
- {
- public:
- UnsignWrongKeyException(const std::string &errMsg) : UnsignException(errMsg) {}
- };
-
- namespace Signature
- {
- class PublicKey
- {
- friend class KeyPair;
- public:
- static PublicKey ZERO;
-
- // Throws InvalidSignatureKeySize if size is not PUBLIC_KEY_NUM_BYTES
- PublicKey(const char *data, size_t size);
- PublicKey(const PublicKey &other);
- PublicKey& operator=(const PublicKey &other);
-
- const char* getData() const { return data; }
- size_t getSize() const { return PUBLIC_KEY_NUM_BYTES; }
-
- // Throws UnsignWrongKeyException if signed message was not signed using the matching private key of this public key.
- // Throws UnsignInvalidSizeException if signed message is too small (< SIGNED_HASH_SIZE).
- // Both exceptions are derived from UnsignException
- std::string unsign(const DataView &signedMessage) const;
-
- size_t operator()() const;
- bool operator==(const PublicKey &other) const;
-
- std::string toString() const;
- private:
- PublicKey(){}
- private:
- char data[PUBLIC_KEY_NUM_BYTES];
- };
-
- struct PublicKeyHasher
- {
- size_t operator()(const PublicKey &publicKey) const
- {
- return publicKey();
- }
- };
-
- template <typename ValueType>
- using MapPublicKey = std::unordered_map<PublicKey, ValueType, PublicKeyHasher>;
-
- class PrivateKey
- {
- friend class KeyPair;
- public:
- // Throws InvalidSignatureKeySize if size is not PRIVATE_KEY_NUM_BYTES
- PrivateKey(const char *data, size_t size);
- PrivateKey(const PrivateKey &other);
- PrivateKey& operator=(const PrivateKey &other);
-
- const char* getData() const { return data; }
- size_t getSize() const { return PRIVATE_KEY_NUM_BYTES; }
-
- // Throws DataSignException if signing data failed for whatever reason. This wont happen unless there is an issue with the private key
- std::string sign(const DataView &dataToSign) const;
- std::string toString() const;
- private:
- PrivateKey(){}
- private:
- char data[PRIVATE_KEY_NUM_BYTES];
- };
-
- class KeyPair
- {
- public:
- // Throws SignatureGenerationException if generation of private/public key pair fails (should never happen)
- KeyPair();
-
- const PublicKey& getPublicKey() const { return publicKey; }
- const PrivateKey& getPrivateKey() const { return privateKey; }
- private:
- PublicKey publicKey;
- PrivateKey privateKey;
- };
- }
-}