From 5a8727e34b938b70623ca865273fd81c7604b461 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 13 Mar 2018 06:26:06 +0100 Subject: Expose include dir --- include/Signature.hpp | 126 -------------------------------------------------- 1 file changed, 126 deletions(-) delete mode 100644 include/Signature.hpp (limited to 'include/Signature.hpp') 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 -#include - -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 - using MapPublicKey = std::unordered_map; - - 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; - }; - } -} -- cgit v1.2.3