diff options
Diffstat (limited to 'include/Encryption.hpp')
-rw-r--r-- | include/Encryption.hpp | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/include/Encryption.hpp b/include/Encryption.hpp deleted file mode 100644 index 4697b35..0000000 --- a/include/Encryption.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -/* - * Encrypts/decrypts data using xchacha20-poly1305 ietf - */ - -#include "DataView.hpp" -#include "utils.hpp" -#include <string> -#include <stdexcept> - -namespace odhtdb -{ - const int NONCE_BYTE_SIZE = 24; - const int KEY_BYTE_SIZE = 32; - - class EncryptionException : public std::runtime_error - { - public: - EncryptionException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - - class DecryptionException : public std::runtime_error - { - public: - DecryptionException(const std::string &errMsg) : std::runtime_error(errMsg) {} - }; - - class Encryption - { - DISABLE_COPY(Encryption) - public: - // Throws EncryptionException on failure (or std::bad_alloc on failed memory allocation) - Encryption(const DataView &data, const DataView &additionalData = DataView(), const DataView &key = DataView()); - ~Encryption(); - - DataView getKey() const; - DataView getNonce() const; - DataView getCipherText() const; - private: - unsigned char key[KEY_BYTE_SIZE]; - unsigned char nonce[NONCE_BYTE_SIZE]; - unsigned char *cipherText; - unsigned long long cipherTextLength; - }; - - class Decryption - { - DISABLE_COPY(Decryption) - public: - Decryption() : decryptedText(nullptr), decryptedTextLength(0) {} - - // Throws DecryptionException on failure - Decryption(const DataView &data, const DataView &nonce, const DataView &key); - Decryption(Decryption &&other); - Decryption& operator=(Decryption &&other); - ~Decryption(); - - DataView getDecryptedText() const; - private: - unsigned char *decryptedText; - unsigned long long decryptedTextLength; - }; -} |