aboutsummaryrefslogtreecommitdiff
path: root/include
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
parent7d9b97b437252df8a481816d50b0fa8587fa69c9 (diff)
Sign messages/verify message signatures
Diffstat (limited to 'include')
-rw-r--r--include/Database.hpp5
-rw-r--r--include/Signature.hpp28
-rw-r--r--include/StagedObject.hpp6
3 files changed, 32 insertions, 7 deletions
diff --git a/include/Database.hpp b/include/Database.hpp
index 0104a6e..e8b35bb 100644
--- a/include/Database.hpp
+++ b/include/Database.hpp
@@ -12,7 +12,6 @@
namespace odhtdb
{
- class Group;
class LocalUser;
class Database
@@ -22,8 +21,8 @@ namespace odhtdb
~Database();
void seed();
- void create(const Key &key, Group *primaryAdminGroup);
- void add(const Key &key, DataView data, LocalUser *creator);
+ void create(LocalUser *owner, const Key &key);
+ void add(LocalUser *owner, const Key &key, DataView data);
void commit();
private:
void commitStagedCreateObject(const StagedCreateObject &stagedObject);
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(){}
diff --git a/include/StagedObject.hpp b/include/StagedObject.hpp
index dc2aaf4..fccf4f6 100644
--- a/include/StagedObject.hpp
+++ b/include/StagedObject.hpp
@@ -26,13 +26,13 @@ namespace odhtdb
struct StagedAddObject
{
Key key;
- DataView data;
+ std::unique_ptr<std::string> data;
u64 timestamp; // In microseconds
Signature::PublicKey creatorPublicKey;
StagedAddObject() : key(), data(), timestamp(0), creatorPublicKey(Signature::PublicKey::ZERO) {}
- StagedAddObject(const Key &_key, const DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey) :
- key(_key), data(_data), timestamp(_timestamp), creatorPublicKey(_creatorPublicKey)
+ StagedAddObject(const Key &_key, std::unique_ptr<std::string> &&_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey) :
+ key(_key), data(std::move(_data)), timestamp(_timestamp), creatorPublicKey(_creatorPublicKey)
{
}