-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_factory.cpp
More file actions
96 lines (71 loc) · 3.05 KB
/
test_factory.cpp
File metadata and controls
96 lines (71 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* This file is part of the headcode.space crypt.
*
* The 'LICENSE.txt' file in the project root holds the software license.
* Copyright (C) 2020-2021 headcode.space e.U.
* Oliver Maurhart <info@headcode.space>, https://www.headcode.space
*/
#include <gtest/gtest.h>
#include <headcode/crypt/crypt.hpp>
TEST(Factory, unknown_algorithm) {
auto algo = headcode::crypt::Factory::Create("UNKNOWN-ALGORITHM");
ASSERT_EQ(algo.get(), nullptr);
}
TEST(Factory, list_symmetric_cipher) {
auto algorithms = headcode::crypt::Factory::GetAlgorithmDescriptions();
std::uint64_t symmetric_cyphers_count{0};
for (auto const & [name, description] : algorithms) {
if (description.family_ == headcode::crypt::Family::kSymmetricCipher) {
symmetric_cyphers_count++;
}
}
std::uint64_t expected_count = 13ul;
#ifdef OPENSSL
expected_count += 12ul;
#endif
EXPECT_EQ(symmetric_cyphers_count, expected_count);
EXPECT_NE(algorithms.find("copy"), algorithms.end());
}
TEST(Factory, list_hashes) {
auto algorithms = headcode::crypt::Factory::GetAlgorithmDescriptions();
std::uint64_t hashes_count{0};
for (auto const & [name, description] : algorithms) {
if (description.family_ == headcode::crypt::Family::kHash) {
hashes_count++;
}
}
std::uint64_t expected_count = 12ul;
#ifdef OPENSSL
expected_count += 7ul;
#endif
EXPECT_EQ(hashes_count, expected_count);
EXPECT_NE(algorithms.find("nohash"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-md5"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-ripemd128"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-ripemd160"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-ripemd256"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-ripemd320"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-sha1"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-sha224"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-sha256"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-sha384"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-sha512"), algorithms.end());
EXPECT_NE(algorithms.find("ltc-tiger192"), algorithms.end());
#ifdef OPENSSL
EXPECT_NE(algorithms.find("openssl-md5"), algorithms.end());
EXPECT_NE(algorithms.find("openssl-ripemd160"), algorithms.end());
EXPECT_NE(algorithms.find("openssl-sha1"), algorithms.end());
EXPECT_NE(algorithms.find("openssl-sha224"), algorithms.end());
EXPECT_NE(algorithms.find("openssl-sha256"), algorithms.end());
EXPECT_NE(algorithms.find("openssl-sha384"), algorithms.end());
EXPECT_NE(algorithms.find("openssl-sha512"), algorithms.end());
#endif
}
TEST(Factory, list_unknown) {
// every algorithm must belong to a known family
auto algorithms = headcode::crypt::Factory::GetAlgorithmDescriptions();
auto some_unknown = std::any_of(algorithms.begin(), algorithms.end(), [](auto const & p) {
return p.second.family_ == headcode::crypt::Family::kUnknown;
});
EXPECT_FALSE(some_unknown);
}