Luna/tests/libluna/TestSHA.cpp
apio 31c36b9b83
All checks were successful
Build and test / build (push) Successful in 2m22s
tests: Add tests for SHA256
2024-07-20 16:34:31 +02:00

39 lines
806 B
C++

#include <luna/SHA.h>
#include <string.h>
#include <test.h>
TestResult test_empty_string_hash()
{
SHA256 sha;
auto digest = TRY(sha.digest());
auto string = TRY(digest.to_string());
validate(string.view() == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
test_success;
}
TestResult test_known_string_hash()
{
const char* text = "Hello, world!";
SHA256 sha;
TRY(sha.append((const u8*)text, strlen(text)));
auto digest = TRY(sha.digest());
auto string = TRY(digest.to_string());
validate(string.view() == "315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3");
test_success;
}
Result<void> test_main()
{
test_prelude;
run_test(test_empty_string_hash);
run_test(test_known_string_hash);
return {};
}