This commit is contained in:
2023-06-02 12:51:08 +02:00
commit 0e355fbe42
142 changed files with 10281 additions and 0 deletions

40
tests/crypto/AESTest.cpp Normal file
View File

@@ -0,0 +1,40 @@
//
// Created by Stepan Usatiuk on 30.04.2023.
//
#include "AESTest.h"
#include "../../src/crypto/AES.h"
std::unique_ptr<TestGroup> AESTest::operator()() {
auto tg = std::make_unique<TestGroup>("AES tests");
tg->addTest(std::make_unique<Test>("Simple AESTest test", std::function<bool()>([]() {
std::string in = "hello1";
auto enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
auto dec = AES::decrypt(enc, "p1", "e");
HelpfulAssert<std::string>()(in, std::string(dec.begin(), dec.end()));
in = "1234567890asdfg";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
dec = AES::decrypt(enc, "p1", "e");
HelpfulAssert<std::string>()(in, std::string(dec.begin(), dec.end()));
in = "1234567890asdfgh";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
dec = AES::decrypt(enc, "p1", "e");
HelpfulAssert<std::string>()(in, std::string(dec.begin(), dec.end()));
in = "1234567890asdfghe";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
dec = AES::decrypt(enc, "p1", "e");
HelpfulAssert<std::string>()(in, std::string(dec.begin(), dec.end()));
in = "1234567890asdfgheq";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
dec = AES::decrypt(enc, "p1", "e");
HelpfulAssert<std::string>()(in, std::string(dec.begin(), dec.end()));
return true;
})));
return tg;
}

16
tests/crypto/AESTest.h Normal file
View File

@@ -0,0 +1,16 @@
//
// Created by Stepan Usatiuk on 30.04.2023.
//
#ifndef SEMBACKUP_AESTEST_H
#define SEMBACKUP_AESTEST_H
#include "../utils/TestGroupGenerator.h"
class AESTest : public TestGroupGenerator {
public:
std::unique_ptr<TestGroup> operator()() override;
};
#endif//SEMBACKUP_AESTEST_H

25
tests/crypto/MD5Test.cpp Normal file
View File

@@ -0,0 +1,25 @@
//
// Created by Stepan Usatiuk on 15.04.2023.
//
#include "MD5Test.h"
std::unique_ptr<TestGroup> MD5Test::operator()() {
auto tg = std::make_unique<TestGroup>("MD5 tests");
tg->addTest(std::make_unique<Test>("Simple MD5 test", std::function<bool()>([]() {
std::vector<char> data{'h', 'e', 'l', 'l', 'o'};
std::array<unsigned char, 16> excepted{0x5d, 0x41, 0x40, 0x2a, 0xbc, 0x4b, 0x2a, 0x76, 0xb9, 0x71, 0x9d, 0x91, 0x10, 0x17, 0xc5, 0x92};
auto out = MD5::calculate(data);
HelpfulAssert<size_t>()(out.size(), 16);
for (int i = 0; i < out.size(); i++) {
HelpfulAssert<unsigned char>()(out[i], excepted[i]);
}
return true;
})));
return tg;
}

17
tests/crypto/MD5Test.h Normal file
View File

@@ -0,0 +1,17 @@
//
// Created by Stepan Usatiuk on 15.04.2023.
//
#ifndef SEMBACKUP_MD5TEST_H
#define SEMBACKUP_MD5TEST_H
#include "../../src/crypto/MD5.h"
#include "../utils/TestGroupGenerator.h"
class MD5Test : public TestGroupGenerator {
public:
std::unique_ptr<TestGroup> operator()() override;
};
#endif//SEMBACKUP_MD5TEST_H