diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/main.cpp b/tests/main.cpp index 1940c1a..57b6cbd 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,7 +1,8 @@ -#include <vector> #include "../include/Database.hpp" #include "../include/Group.hpp" #include "../include/LocalUser.hpp" +#include "../include/Encryption.hpp" +#include <vector> #include <chrono> #include <thread> @@ -9,7 +10,7 @@ using namespace std; using namespace chrono_literals; using namespace odhtdb; -#define assertEquals(a, b) do { if((a) != (b)) { fprintf(stderr, "Assert failed:\n%s != %s\n", #a, #b); exit(1); } } while(0) +#define assertEquals(expected, actual) do { if((expected) != (actual)) { fprintf(stderr, "Assert failed:\nExpected: %s, actual: %s\n", #expected, #actual); exit(1); } } while(0) void fail(const string &errMsg) { fprintf(stderr, "Fail:\n%.*s\n", errMsg.size(), errMsg.c_str()); } void testSignData(LocalUser *localUser) @@ -62,10 +63,32 @@ void testSignData(LocalUser *localUser) } } +void testEncryption() +{ + EncryptionKey encryptionKey; + generateEncryptionKey(&encryptionKey); + + const char *message = "hello, world!"; + const unsigned long long messageLength = 13; + EncryptedData encryptedData; + int encrypted = encrypt(&encryptedData, &encryptionKey, message, messageLength); + if(encrypted != 0) + fail("Failed to encrypt data"); + + std::string decryptedText; + int decrypted = decrypt(&decryptedText, &encryptionKey, &encryptedData); + if(decrypted != 0) + fail("Failed to decrypt data"); + + assertEquals(messageLength, decryptedText.size()); + assertEquals(0, strncmp(message, decryptedText.c_str(), messageLength)); +} + int main() { LocalUser *localUser = LocalUser::create(Signature::KeyPair(), "dec05eba"); testSignData(localUser); + testEncryption(); // TODO: For tests, dont run against bootstrap.ring.cx. // Run against a bootstrap node made only for testing which doesn't persist added data. |