summaryrefslogtreecommitdiff
path: root/test/buildtool/crypto/crypto.test.cpp
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2022-06-15 18:51:47 +0200
committerOliver Reiche <oliver.reiche@huawei.com>2022-06-20 15:23:02 +0200
commit855affd9b681d98f248009ddb2c1abe987029f72 (patch)
tree6d4dbfc2c99020772313f381d2f793950d2b03f4 /test/buildtool/crypto/crypto.test.cpp
parent391d982f2fbd98a2973f14e0b5969f66c2abd756 (diff)
downloadjustbuild-855affd9b681d98f248009ddb2c1abe987029f72.tar.gz
Crypto: Refactor hash computation
... by renaming HashGenerator to (incremental) Hasher and dropping support for Git/MD5 hashes. The Hasher does not expose the actual hash implementation.
Diffstat (limited to 'test/buildtool/crypto/crypto.test.cpp')
-rw-r--r--test/buildtool/crypto/crypto.test.cpp57
1 files changed, 0 insertions, 57 deletions
diff --git a/test/buildtool/crypto/crypto.test.cpp b/test/buildtool/crypto/crypto.test.cpp
deleted file mode 100644
index 78bea66b..00000000
--- a/test/buildtool/crypto/crypto.test.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include <algorithm>
-
-#include "catch2/catch.hpp"
-#include "src/buildtool/crypto/hash_generator.hpp"
-
-template <HashGenerator::HashType type>
-void test_single_hash(std::string const& bytes, std::string const& result) {
- HashGenerator hash_gen{type};
- auto digest = hash_gen.Run(bytes);
- CHECK(digest.HexString() == result);
-}
-
-template <HashGenerator::HashType type>
-void test_increment_hash(std::string const& bytes, std::string const& result) {
- HashGenerator hash_gen{type};
- auto hasher = hash_gen.IncrementalHasher();
- hasher.Update(bytes);
- auto digest = std::move(hasher).Finalize();
- CHECK(digest);
- CHECK(digest->HexString() == result);
-}
-
-TEST_CASE("Hash Generator", "[crypto]") {
- std::string bytes{"test"};
-
- SECTION("MD5") {
- // same as: echo -n test | md5sum
- test_single_hash<HashGenerator::HashType::MD5>(
- bytes, "098f6bcd4621d373cade4e832627b4f6");
- test_increment_hash<HashGenerator::HashType::MD5>(
- bytes, "098f6bcd4621d373cade4e832627b4f6");
- }
-
- SECTION("SHA-1") {
- // same as: echo -n test | sha1sum
- test_single_hash<HashGenerator::HashType::SHA1>(
- bytes, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3");
- test_increment_hash<HashGenerator::HashType::SHA1>(
- bytes, "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3");
- }
-
- SECTION("SHA-256") {
- // same as: echo -n test | sha256sum
- test_single_hash<HashGenerator::HashType::SHA256>(
- bytes,
- "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
- test_increment_hash<HashGenerator::HashType::SHA256>(
- bytes,
- "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
- }
-
- SECTION("Git") {
- // same as: echo -n test | git hash-object --stdin
- test_single_hash<HashGenerator::HashType::GIT>(
- bytes, "30d74d258442c7c65512eafab474568dd706c430");
- }
-}