aboutsummaryrefslogtreecommitdiff
path: root/include/Signature.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-02-14 22:18:48 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:12 +0200
commit40d94ad83f74753b71f33b58be8664bb21200219 (patch)
tree7ebe59b3e9a8872cf4c3c49f14f564827810a1e3 /include/Signature.hpp
parent7d9b97b437252df8a481816d50b0fa8587fa69c9 (diff)
Sign messages/verify message signatures
Diffstat (limited to 'include/Signature.hpp')
-rw-r--r--include/Signature.hpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/include/Signature.hpp b/include/Signature.hpp
index ea776ea..aace383 100644
--- a/include/Signature.hpp
+++ b/include/Signature.hpp
@@ -1,11 +1,13 @@
#pragma once
+#include "DataView.hpp"
#include <stdexcept>
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
{
@@ -25,6 +27,25 @@ namespace odhtdb
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
@@ -41,6 +62,11 @@ namespace odhtdb
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;
+
std::string toString() const;
private:
PublicKey(){}
@@ -61,7 +87,7 @@ namespace odhtdb
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 std::string &dataToSign) const;
+ std::string sign(const DataView &dataToSign) const;
std::string toString() const;
private:
PrivateKey(){}