Replace Decryptor CRTP base with a concept.
Chaos Ci / test (push) Successful in 3m4s
Chaos Ci / benchmark (push) Successful in 1m31s

This commit is contained in:
hashlag
2026-09-06 02:45:45 +03:00
parent 2c6a24197a
commit 3dacd57fef
3 changed files with 28 additions and 43 deletions
@@ -529,9 +529,9 @@ TEST(DesCryptTests, EncryptUInt64BlockGenericTest)
ASSERT_EQ(expected, EncryptUInt64BlockGeneric(enc, data));
}
template<typename Impl, typename InputIt>
static std::vector<uint8_t> DecryptThroughBase(const Decryptor<Impl> & dec,
InputIt begin, InputIt end)
template<Decryptor DecryptorImpl, typename InputIt>
static std::vector<uint8_t> DecryptGeneric(const DecryptorImpl & dec,
InputIt begin, InputIt end)
{
std::vector<uint8_t> result;
result.resize(dec.GetBlockSize(), 0);
@@ -540,7 +540,7 @@ static std::vector<uint8_t> DecryptThroughBase(const Decryptor<Impl> & dec,
return result;
}
TEST(DesCryptTests, DecryptThroughBaseTest)
TEST(DesCryptTests, DecryptGenericTest)
{
std::array<uint8_t, DesCrypt::KeySize> key = { 0x13, 0x34, 0x57, 0x79, 0x9b, 0xbc, 0xdf, 0xf1 };
@@ -550,16 +550,16 @@ TEST(DesCryptTests, DecryptThroughBaseTest)
DesCrypt::Key desKey(key.begin(), key.end());
DesCrypt::Decryptor dec(desKey);
ASSERT_EQ(expected, DecryptThroughBase(dec, data.begin(), data.end()));
ASSERT_EQ(expected, DecryptGeneric(dec, data.begin(), data.end()));
}
template<typename Impl>
static uint64_t DecryptUInt64BlockThroughBase(const Decryptor<Impl> & dec, uint64_t block)
template<Decryptor DecryptorImpl>
static uint64_t DecryptUInt64BlockGeneric(const DecryptorImpl & dec, uint64_t block)
{
return dec.DecryptBlock(block);
}
TEST(DesCryptTests, DecryptUInt64BlockThroughBaseTest)
TEST(DesCryptTests, DecryptUInt64BlockGenericTest)
{
std::array<uint8_t, DesCrypt::KeySize> key = { 0x13, 0x34, 0x57, 0x79, 0x9b, 0xbc, 0xdf, 0xf1 };
@@ -569,5 +569,5 @@ TEST(DesCryptTests, DecryptUInt64BlockThroughBaseTest)
DesCrypt::Key desKey(key.begin(), key.end());
DesCrypt::Decryptor dec(desKey);
ASSERT_EQ(expected, DecryptUInt64BlockThroughBase(dec, data));
ASSERT_EQ(expected, DecryptUInt64BlockGeneric(dec, data));
}