42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
//
|
|
// Created by dongwenzhe on 2023/3/14.
|
|
//
|
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|
#include "doctest.h"
|
|
#include "crypto.h"
|
|
|
|
TEST_SUITE("Crypto functions") {
|
|
TEST_CASE("BASE64") {
|
|
auto *pSrc = (unsigned char *)"HELLOWORLD";
|
|
const char *encode;
|
|
|
|
encode = base64_encode(pSrc, 16);
|
|
INFO("BASE64_ENCODING:", encode);
|
|
|
|
unsigned char *decode;
|
|
unsigned int outputSize = 0;
|
|
decode = base64_decode(encode, &outputSize);
|
|
INFO("BASE64_DECODING:", decode);
|
|
|
|
for(int i = 0; i<outputSize; i++) {
|
|
CHECK_EQ(decode[i], pSrc[i]);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("AES") {
|
|
AES_TYPE algoType = DES3_CBC_PKCS7PADDING;
|
|
const char *data = "hello world";
|
|
const char *key = "NmmW4zO4FCrhpugLaoBgjA==";
|
|
unsigned char *out;
|
|
unsigned char *res;
|
|
int outputSize = 0;
|
|
int resSize = 0;
|
|
|
|
symmetric_encrypto(algoType, (unsigned char *)data, strlen(data), &out, &outputSize, key);
|
|
CHECK_NE(out, nullptr);
|
|
symmetric_decrypto(algoType, out, outputSize, &res, &resSize, key);
|
|
CHECK_NE(res, nullptr);
|
|
REQUIRE_MESSAGE((strlen(data) == resSize), "the decrypted message:", res);
|
|
}
|
|
}
|