Compare commits

..
1 Commits
Author SHA1 Message Date
hashlag 4d613d8015 Introduce BlockAdapter.
Chaos Ci / test (push) Successful in 3m23s
Chaos Ci / benchmark (push) Successful in 1m33s
2026-10-12 01:05:14 +03:00
19 changed files with 197 additions and 265 deletions

No files matched your search

-7
View File
@@ -1,7 +0,0 @@
returnByReference:Chaos/Hash/Md4.hpp:141
returnByReference:Chaos/Hash/Md5.hpp:165
returnByReference:Chaos/Hash/Sha1.hpp:134
useInitializationList:Chaos/Service/SeArray.hpp:25
accessMoved:ChaosTests/Service/SeArrayTests.cpp:309
accessMoved:ChaosTests/Service/SeArrayTests.cpp:331
accessMoved:ChaosTests/Service/SeArrayTests.cpp:367
-32
View File
@@ -58,38 +58,6 @@ jobs:
include-hidden-files: true include-hidden-files: true
retention-days: 10 retention-days: 10
static-analysis:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Install
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake cppcheck
- name: Generate compile commands
run: |
mkdir build-debug
cmake -S . -B build-debug/ -D CMAKE_BUILD_TYPE=Debug -D CMAKE_EXPORT_COMPILE_COMMANDS=ON
- name: Run cppcheck
run: |
cppcheck --version
cppcheck --project=build-debug/compile_commands.json \
--file-filter='*ChaosTests/*' \
--file-filter='*ChaosBenches/*' \
--enable=warning,performance,portability \
--suppress='*:*/_deps/*' \
--suppress=missingIncludeSystem \
--suppressions-list=.cppcheck \
--inline-suppr \
--error-exitcode=1
benchmark: benchmark:
runs-on: ubuntu-latest runs-on: ubuntu-latest
+53
View File
@@ -0,0 +1,53 @@
#ifndef CHAOS_CIPHER_BLOCK_BLOCKADAPTER_HPP
#define CHAOS_CIPHER_BLOCK_BLOCKADAPTER_HPP
#include <cstdint>
#include <vector>
namespace Chaos::Cipher::Block
{
template<typename ModeT>
class BlockAdapter
{
public:
class Key
{
friend class BlockAdapter;
public:
template<typename InputIt>
Key(InputIt keyBegin, InputIt keyEnd)
: Key_(keyBegin, keyEnd)
{ }
template<typename Byte>
Key(const std::vector<Byte> & key)
: Key_(key.cbegin(), key.cend())
{ }
private:
ModeT::Cipher::Key Key_;
};
template<typename Byte>
static std::vector<Byte> Encrypt(const Key & key, const std::vector<Byte> & plaintext)
{
typename ModeT::Encryptor encryptor(key.Key_);
std::vector<Byte> result;
const uint64_t maxResultSize = encryptor.PredictMaxUpdateOutput(plaintext.size()) +
encryptor.PredictMaxFinishOutput();
result.resize(maxResultSize);
uint64_t written = encryptor.Update(result.begin(), result.end(),
plaintext.begin(), plaintext.end());
written += encryptor.Finish(result.begin() + written, result.end());
result.resize(written);
return result;
}
};
} // namespace Chaos::Cipher::Block
#endif // CHAOS_CIPHER_BLOCK_BLOCKADAPTER_HPP
-30
View File
@@ -114,12 +114,6 @@ public:
Decrypt Decrypt
}; };
KeySchedule(const KeySchedule & other) = delete;
KeySchedule(KeySchedule && other) = delete;
KeySchedule & operator=(const KeySchedule & other) = delete;
KeySchedule & operator=(KeySchedule && other) = delete;
KeySchedule(Direction direction, const RawKey & rawKey) KeySchedule(Direction direction, const RawKey & rawKey)
{ {
Key56 key56 = Pc1(Bitwise::PackUInt64(rawKey.Begin(), rawKey.End())); Key56 key56 = Pc1(Bitwise::PackUInt64(rawKey.Begin(), rawKey.End()));
@@ -216,22 +210,10 @@ public:
DesCrypt() = delete; DesCrypt() = delete;
DesCrypt(const DesCrypt & other) = delete;
DesCrypt(DesCrypt && other) = delete;
DesCrypt & operator=(const DesCrypt & other) = delete;
DesCrypt & operator=(DesCrypt && other) = delete;
class Key class Key
{ {
friend class DesCrypt; friend class DesCrypt;
public: public:
Key(const Key & other) = delete;
Key(Key && other) = delete;
Key & operator=(const Key & other) = delete;
Key & operator=(Key && other) = delete;
template<typename InputIt> template<typename InputIt>
Key(InputIt keyBegin, InputIt keyEnd) Key(InputIt keyBegin, InputIt keyEnd)
{ {
@@ -263,12 +245,6 @@ public:
static constexpr size_t BlockSize = DesCrypt::BlockSize; static constexpr size_t BlockSize = DesCrypt::BlockSize;
static constexpr size_t KeySize = DesCrypt::KeySize; static constexpr size_t KeySize = DesCrypt::KeySize;
Encryptor(const Encryptor & other) = delete;
Encryptor(Encryptor && other) = delete;
Encryptor & operator=(const Encryptor & other) = delete;
Encryptor & operator=(Encryptor && other) = delete;
Encryptor(const Key & key) Encryptor(const Key & key)
: Schedule_(Inner_::KeySchedule::Direction::Encrypt, key.Key_) : Schedule_(Inner_::KeySchedule::Direction::Encrypt, key.Key_)
{ } { }
@@ -317,12 +293,6 @@ public:
static constexpr size_t BlockSize = DesCrypt::BlockSize; static constexpr size_t BlockSize = DesCrypt::BlockSize;
static constexpr size_t KeySize = DesCrypt::KeySize; static constexpr size_t KeySize = DesCrypt::KeySize;
Decryptor(const Decryptor & other) = delete;
Decryptor(Decryptor && other) = delete;
Decryptor & operator=(const Decryptor & other) = delete;
Decryptor & operator=(Decryptor && other) = delete;
Decryptor(const Key & key) Decryptor(const Key & key)
: Schedule_(Inner_::KeySchedule::Direction::Decrypt, key.Key_) : Schedule_(Inner_::KeySchedule::Direction::Decrypt, key.Key_)
{ } { }
-20
View File
@@ -19,23 +19,9 @@ public:
using Cipher = CipherT; using Cipher = CipherT;
using Padder = PadderT; using Padder = PadderT;
EcbMode() = delete;
EcbMode(const EcbMode & other) = delete;
EcbMode(EcbMode && other) = delete;
EcbMode & operator=(const EcbMode & other) = delete;
EcbMode & operator=(EcbMode && other) = delete;
class Encryptor class Encryptor
{ {
public: public:
Encryptor(const Encryptor & other) = delete;
Encryptor(Encryptor && other) = delete;
Encryptor & operator=(const Encryptor & other) = delete;
Encryptor & operator=(Encryptor && other) = delete;
Encryptor(const typename CipherT::Key & key) Encryptor(const typename CipherT::Key & key)
: Encryptor_(key) : Encryptor_(key)
, BlockBytesPacked_(0) , BlockBytesPacked_(0)
@@ -129,12 +115,6 @@ public:
class Decryptor class Decryptor
{ {
public: public:
Decryptor(const Decryptor & other) = delete;
Decryptor(Decryptor && other) = delete;
Decryptor & operator=(const Decryptor & other) = delete;
Decryptor & operator=(Decryptor && other) = delete;
Decryptor(const typename CipherT::Key & key) Decryptor(const typename CipherT::Key & key)
: Decryptor_(key) : Decryptor_(key)
, BlockBytesPacked_(0) , BlockBytesPacked_(0)
-6
View File
@@ -17,12 +17,6 @@ public:
Arc4Crypt() Arc4Crypt()
{ } { }
Arc4Crypt(const Arc4Crypt & other) = delete;
Arc4Crypt(Arc4Crypt && other) = delete;
Arc4Crypt & operator=(const Arc4Crypt & other) = delete;
Arc4Crypt & operator=(Arc4Crypt && other) = delete;
template<typename InputIt> template<typename InputIt>
Arc4Crypt(InputIt keyBegin, InputIt keyEnd) Arc4Crypt(InputIt keyBegin, InputIt keyEnd)
{ {
-8
View File
@@ -16,16 +16,8 @@ class Arc4Gen
public: public:
Arc4Gen() Arc4Gen()
: IsInitialized_(false) : IsInitialized_(false)
, I_(0)
, J_(0)
{ } { }
Arc4Gen(const Arc4Gen & other) = delete;
Arc4Gen(Arc4Gen && other) = delete;
Arc4Gen & operator=(const Arc4Gen & other) = delete;
Arc4Gen & operator=(Arc4Gen && other) = delete;
template<typename InputIt> template<typename InputIt>
Arc4Gen(InputIt keyBegin, InputIt keyEnd) Arc4Gen(InputIt keyBegin, InputIt keyEnd)
{ {
-6
View File
@@ -175,12 +175,6 @@ public:
ResetImpl(); ResetImpl();
} }
Md4Hasher(const Md4Hasher & other) = delete;
Md4Hasher(Md4Hasher && other) = delete;
Md4Hasher & operator=(const Md4Hasher & other) = delete;
Md4Hasher & operator=(Md4Hasher && other) = delete;
void Reset() void Reset()
{ {
ResetImpl(); ResetImpl();
-6
View File
@@ -199,12 +199,6 @@ public:
ResetImpl(); ResetImpl();
} }
Md5Hasher(const Md5Hasher & other) = delete;
Md5Hasher(Md5Hasher && other) = delete;
Md5Hasher & operator=(const Md5Hasher & other) = delete;
Md5Hasher & operator=(Md5Hasher && other) = delete;
void Reset() void Reset()
{ {
ResetImpl(); ResetImpl();
-6
View File
@@ -169,12 +169,6 @@ public:
ResetImpl(); ResetImpl();
} }
Sha1Hasher(const Sha1Hasher & other) = delete;
Sha1Hasher(Sha1Hasher && other) = delete;
Sha1Hasher & operator=(const Sha1Hasher & other) = delete;
Sha1Hasher & operator=(Sha1Hasher && other) = delete;
void Reset() void Reset()
{ {
ResetImpl(); ResetImpl();
+11 -17
View File
@@ -1,10 +1,10 @@
#ifndef CHAOS_MAC_HMAC_HPP #ifndef CHAOS_MAC_HMAC_HPP
#define CHAOS_MAC_HMAC_HPP #define CHAOS_MAC_HMAC_HPP
#include <array>
#include <cstdint> #include <cstdint>
#include "Hash/Hasher.hpp" #include "Hash/Hasher.hpp"
#include "Service/SeArray.hpp"
#include "Service/ChaosException.hpp" #include "Service/ChaosException.hpp"
namespace Chaos::Mac::Hmac namespace Chaos::Mac::Hmac
@@ -18,12 +18,6 @@ public:
: IsInitialized_(false) : IsInitialized_(false)
{ } { }
Hmac(const Hmac & other) = delete;
Hmac(Hmac && other) = delete;
Hmac & operator=(const Hmac & other) = delete;
Hmac & operator=(Hmac && other) = delete;
template<typename InputIt> template<typename InputIt>
Hmac(InputIt keyBegin, InputIt keyEnd) Hmac(InputIt keyBegin, InputIt keyEnd)
{ {
@@ -52,14 +46,14 @@ public:
Hasher_.Reset(); Hasher_.Reset();
KeyType opaddedKey = PadKey<OPAD_BYTE>(Key_); KeyType opaddedKey = PadKey<OPAD_BYTE>(Key_);
Hasher_.Update(opaddedKey.Begin(), opaddedKey.End()); Hasher_.Update(opaddedKey.begin(), opaddedKey.end());
Hasher_.Update(innerDigest.begin(), innerDigest.end()); Hasher_.Update(innerDigest.begin(), innerDigest.end());
return Hasher_.Finish(); return Hasher_.Finish();
} }
private: private:
using KeyType = Service::SeArray<uint8_t, HasherImpl::BlockSize>; using KeyType = std::array<uint8_t, HasherImpl::BlockSize>;
static constexpr uint8_t OPAD_BYTE = 0x5c; static constexpr uint8_t OPAD_BYTE = 0x5c;
static constexpr uint8_t IPAD_BYTE = 0x36; static constexpr uint8_t IPAD_BYTE = 0x36;
@@ -81,12 +75,12 @@ private:
static KeyType GenerateKey(InputIt keyBegin, InputIt keyEnd) static KeyType GenerateKey(InputIt keyBegin, InputIt keyEnd)
{ {
KeyType key; KeyType key;
key.Fill(0); key.fill(0);
InputIt keyIt = keyBegin; InputIt keyIt = keyBegin;
uint64_t idx = 0; uint64_t idx = 0;
for (; keyIt != keyEnd && idx < key.Size(); for (; keyIt != keyEnd && idx < key.size();
++keyIt, ++idx) ++keyIt, ++idx)
{ {
key[idx] = *keyIt; key[idx] = *keyIt;
@@ -96,17 +90,17 @@ private:
{ {
HasherImpl keyHasher; HasherImpl keyHasher;
keyHasher.Update(key.Begin(), key.End()); keyHasher.Update(key.begin(), key.end());
keyHasher.Update(keyIt, keyEnd); keyHasher.Update(keyIt, keyEnd);
auto digest = keyHasher.Finish().GetRawDigest(); auto digest = keyHasher.Finish().GetRawDigest();
static_assert(digest.size() <= HasherImpl::BlockSize); static_assert(digest.size() <= HasherImpl::BlockSize);
key.Fill(0); key.fill(0);
idx = 0; idx = 0;
for (auto it = digest.begin(); for (auto it = digest.begin();
it != digest.end() && idx < key.Size(); it != digest.end() && idx < key.size();
++it, ++idx) ++it, ++idx)
{ {
key[idx] = *it; key[idx] = *it;
@@ -124,8 +118,8 @@ private:
KeyType paddedKey; KeyType paddedKey;
uint64_t idx = 0; uint64_t idx = 0;
for (auto it = key.Begin(); for (auto it = key.cbegin();
it != key.End() && idx < paddedKey.Size(); it != key.cend() && idx < paddedKey.size();
++it, ++idx) ++it, ++idx)
{ {
paddedKey[idx] = (*it) ^ PAD_BYTE; paddedKey[idx] = (*it) ^ PAD_BYTE;
@@ -141,7 +135,7 @@ private:
Hasher_.Reset(); Hasher_.Reset();
KeyType ipaddedKey = PadKey<IPAD_BYTE>(Key_); KeyType ipaddedKey = PadKey<IPAD_BYTE>(Key_);
Hasher_.Update(ipaddedKey.Begin(), ipaddedKey.End()); Hasher_.Update(ipaddedKey.begin(), ipaddedKey.end());
IsInitialized_ = true; IsInitialized_ = true;
} }
-8
View File
@@ -15,14 +15,6 @@ namespace Chaos::Padding
class PadderIso7816 class PadderIso7816
{ {
public: public:
PadderIso7816() = delete;
PadderIso7816(const PadderIso7816 & other) = delete;
PadderIso7816(PadderIso7816 && other) = delete;
PadderIso7816 & operator=(const PadderIso7816 & other) = delete;
PadderIso7816 & operator=(PadderIso7816 && other) = delete;
template<typename OutputIt> template<typename OutputIt>
static void Pad(OutputIt begin, OutputIt end) static void Pad(OutputIt begin, OutputIt end)
{ {
-8
View File
@@ -16,14 +16,6 @@ namespace Chaos::Padding
class PadderPkcs7 class PadderPkcs7
{ {
public: public:
PadderPkcs7() = delete;
PadderPkcs7(const PadderPkcs7 & other) = delete;
PadderPkcs7(PadderPkcs7 && other) = delete;
PadderPkcs7 & operator=(const PadderPkcs7 & other) = delete;
PadderPkcs7 & operator=(PadderPkcs7 && other) = delete;
template<typename OutputIt> template<typename OutputIt>
static void Pad(OutputIt begin, OutputIt end) static void Pad(OutputIt begin, OutputIt end)
{ {
+2 -21
View File
@@ -4,7 +4,6 @@
#include <array> #include <array>
#include <concepts> #include <concepts>
#include <cstddef> #include <cstddef>
#include <utility>
namespace Chaos::Service namespace Chaos::Service
{ {
@@ -19,28 +18,10 @@ public:
} }
SeArray(const SeArray & other) = delete; SeArray(const SeArray & other) = delete;
SeArray(SeArray && other) = delete;
SeArray(SeArray && other) noexcept
{
Storage_ = std::move(other.Storage_);
other.EraseImpl();
}
SeArray & operator=(const SeArray & other) = default; SeArray & operator=(const SeArray & other) = default;
SeArray & operator=(SeArray && other) = delete;
SeArray & operator=(SeArray && other) noexcept
{
if (this == &other)
{
return *this;
}
EraseImpl();
Storage_ = std::move(other.Storage_);
other.EraseImpl();
return *this;
}
~SeArray() ~SeArray()
{ {
+1
View File
@@ -20,6 +20,7 @@ set(ChaosTests_SOURCE SanCallbacks.cpp
Cipher/Stream/Arc4/Arc4CryptTests.cpp Cipher/Stream/Arc4/Arc4CryptTests.cpp
Cipher/Block/Des/DesCryptTests.cpp Cipher/Block/Des/DesCryptTests.cpp
Cipher/Block/Mode/EcbModeTests.cpp Cipher/Block/Mode/EcbModeTests.cpp
Cipher/Block/BlockAdapterTests.cpp
Padding/PadderPkcs7Tests.cpp Padding/PadderPkcs7Tests.cpp
Padding/PadderIso7816Tests.cpp Padding/PadderIso7816Tests.cpp
Service/SeArrayTests.cpp Service/SeArrayTests.cpp
@@ -0,0 +1,114 @@
#include <gtest/gtest.h>
#include "TestHelpers/AssertThrowEx.hpp"
#include <cstring>
#include <cstdint>
#include <vector>
#include "Cipher/Block/Des/DesCrypt.hpp"
#include "Cipher/Block/Mode/Ecb.hpp"
#include "Cipher/Block/BlockAdapter.hpp"
#include "Padding/PadderPkcs7.hpp"
#include "Service/ChaosException.hpp"
using namespace Chaos::Cipher::Block;
using namespace Chaos::Cipher::Block::Mode;
using namespace Chaos::Padding;
TEST(BlockAdapterTests, EncryptTest)
{
using Adapter = BlockAdapter<EcbMode<Des::DesCrypt, PadderPkcs7>>;
{
const char * str = "smoke and mirrors";
std::vector<uint8_t> data(str, str + strlen(str));
std::vector<uint8_t> key = { 0x0c, 0xfd, 0x01, 0xa3, 0x60, 0xd0, 0x15, 0xa6 };
std::vector<uint8_t> expected = { 0x84, 0x39, 0xcd, 0xe5, 0x1f, 0x3d,
0x2a, 0x11, 0x63, 0xc3, 0x56, 0x28,
0xf5, 0x89, 0xdb, 0xc4, 0xa6, 0xca,
0x52, 0xb3, 0xa8, 0xce, 0x64, 0x2d };
ASSERT_EQ(expected, Adapter::Encrypt(key, data));
}
{
std::vector<uint8_t> data = {};
std::vector<uint8_t> key = { 0xaa, 0xbb, 0xaa, 0xbb, 0xaa, 0xbb, 0xaa, 0xbb };
std::vector<uint8_t> expected = { 0xef, 0xe2, 0x4d, 0xe9, 0x9d, 0xe7, 0x9b, 0xbf };
ASSERT_EQ(expected, Adapter::Encrypt(key, data));
}
{
std::vector<uint8_t> data = { 0x96, 0x9f, 0x42, 0xd3, 0x47, 0x10, 0x4d, 0xb4, 0x89, 0x54,
0x5c, 0xad, 0x0a, 0xb9, 0xac, 0x4e, 0xbf, 0x00, 0x1a, 0x47,
0x3d, 0xd1, 0xe7, 0xb3, 0x70, 0xb7, 0x4e, 0xd9, 0x73, 0x7d,
0xb3, 0x24 };
std::vector<uint8_t> key = { 0xe9, 0xeb, 0x1f, 0xfa, 0x39, 0x95, 0xf0, 0xb9 };
std::vector<uint8_t> expected = { 0x53, 0x06, 0x73, 0x79, 0xb8, 0xd7, 0xbe, 0x5d, 0x6e, 0xa0,
0x1f, 0x03, 0x46, 0x07, 0xd6, 0x48, 0x65, 0x4f, 0x9a, 0x8f,
0x1a, 0xe4, 0xa7, 0x7f, 0x13, 0xc9, 0x06, 0x8c, 0x57, 0xbd,
0x79, 0x5e, 0x3d, 0x21, 0x02, 0x13, 0x5f, 0xae, 0xc9, 0x45 };
ASSERT_EQ(expected, Adapter::Encrypt(key, data));
}
{
std::vector<uint8_t> data = { 0x51, 0x89, 0x9f, 0x0c, 0x32, 0x9b, 0x1d };
uint8_t key[] = { 0x28, 0x1c, 0xf3, 0x11, 0xce, 0xc6, 0xc2, 0x38 };
std::vector<uint8_t> expected = { 0x64, 0x32, 0x13, 0xe7, 0x31, 0x06, 0xc6, 0x6f };
ASSERT_EQ(expected, Adapter::Encrypt({ key, key + std::size(key) }, data));
}
}
TEST(BlockAdapterTests, InvalidKeyTest)
{
using Adapter = BlockAdapter<EcbMode<Des::DesCrypt, PadderPkcs7>>;
{
std::vector<uint8_t> key = { 0x01 };
ASSERT_THROW_EX(Adapter::Key{ key },
Chaos::Service::ChaosException,
{
ASSERT_EQ("DesCrypt::Key: invalid key length (8 bytes required)",
ex.GetMessage());
});
ASSERT_THROW_EX((Adapter::Key{ key.begin(), key.end() }),
Chaos::Service::ChaosException,
{
ASSERT_EQ("DesCrypt::Key: invalid key length (8 bytes required)",
ex.GetMessage());
});
}
{
std::vector<uint8_t> data = { 0x51, 0x89, 0x9f, 0x0c, 0x32, 0x9b, 0x1d };
std::vector<uint8_t> key = { 0xe9, 0xeb, 0x11, 0x1f, 0xfa, 0xb3, 0x39, 0x95, 0xf0, 0xb9 };
ASSERT_THROW_EX(Adapter::Encrypt(key, data),
Chaos::Service::ChaosException,
{
ASSERT_EQ("DesCrypt::Key: invalid key length (8 bytes required)",
ex.GetMessage());
});
}
{
std::vector<uint8_t> data = { 0x51, 0x89, 0x9f, 0x0c, 0x32, 0x9b, 0x1d };
uint8_t key[] = { 0x28, 0x1c, 0xf3, 0x11, 0xce, 0xc6, 0xc2 };
ASSERT_THROW_EX(Adapter::Encrypt({ key, key + std::size(key) }, data),
Chaos::Service::ChaosException,
{
ASSERT_EQ("DesCrypt::Key: invalid key length (8 bytes required)",
ex.GetMessage());
});
}
}
+8 -6
View File
@@ -110,9 +110,9 @@ TEST(PadIso7816Tests, PadOutIteratorUsageTest)
} }
template<Padder PadderImpl, typename OutputIt> template<Padder PadderImpl, typename OutputIt>
void PadGeneric(OutputIt begin, OutputIt end) void PadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
{ {
PadderImpl::Pad(begin, end); padder.Pad(begin, end);
} }
TEST(PadIso7816Tests, PadThroughBaseTest) TEST(PadIso7816Tests, PadThroughBaseTest)
@@ -126,7 +126,8 @@ TEST(PadIso7816Tests, PadThroughBaseTest)
0x80, 0x00, 0x00, 0x00, 0x00 0x80, 0x00, 0x00, 0x00, 0x00
}; };
PadGeneric<PadderIso7816>(fact.begin(), fact.end()); const PadderIso7816 padder;
PadGeneric(padder, fact.begin(), fact.end());
ASSERT_EQ(expected, fact); ASSERT_EQ(expected, fact);
} }
@@ -324,9 +325,9 @@ TEST(PadIso7816Tests, UnpadErrorTest)
} }
template<Padder PadderImpl, typename OutputIt> template<Padder PadderImpl, typename OutputIt>
auto ComputeUnpadGeneric(OutputIt begin, OutputIt end) auto ComputeUnpadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
{ {
return PadderImpl::ComputeUnpad(begin, end); return padder.ComputeUnpad(begin, end);
} }
TEST(PadIso7816Tests, ComputeUnpadThroughBaseTest) TEST(PadIso7816Tests, ComputeUnpadThroughBaseTest)
@@ -334,7 +335,8 @@ TEST(PadIso7816Tests, ComputeUnpadThroughBaseTest)
{ {
std::array<uint8_t, 5> data = { 0x80, 0x00, 0x00, 0x00, 0x00 }; std::array<uint8_t, 5> data = { 0x80, 0x00, 0x00, 0x00, 0x00 };
auto result = ComputeUnpadGeneric<PadderIso7816>(data.begin(), data.end()); const PadderIso7816 padder;
auto result = ComputeUnpadGeneric(padder, data.begin(), data.end());
ASSERT_TRUE(result.IsOkay_); ASSERT_TRUE(result.IsOkay_);
ASSERT_EQ(5, result.PadSize_); ASSERT_EQ(5, result.PadSize_);
+8 -6
View File
@@ -138,9 +138,9 @@ TEST(PadPkcs7Tests, PadOutIteratorUsageTest)
} }
template<Padder PadderImpl, typename OutputIt> template<Padder PadderImpl, typename OutputIt>
void PadGeneric(OutputIt begin, OutputIt end) void PadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
{ {
PadderImpl::Pad(begin, end); padder.Pad(begin, end);
} }
TEST(PadPkcs7Tests, PadThroughBaseTest) TEST(PadPkcs7Tests, PadThroughBaseTest)
@@ -152,7 +152,8 @@ TEST(PadPkcs7Tests, PadThroughBaseTest)
0x05, 0x05, 0x05, 0x05, 0x05 0x05, 0x05, 0x05, 0x05, 0x05
}; };
PadGeneric<PadderPkcs7>(fact.begin(), fact.end()); const PadderPkcs7 padder;
PadGeneric(padder, fact.begin(), fact.end());
ASSERT_EQ(expected, fact); ASSERT_EQ(expected, fact);
} }
@@ -347,9 +348,9 @@ TEST(PadPkcs7Tests, UnpadErrorTest)
} }
template<Padder PadderImpl, typename OutputIt> template<Padder PadderImpl, typename OutputIt>
auto ComputeUnpadGeneric(OutputIt begin, OutputIt end) auto ComputeUnpadGeneric(const PadderImpl & padder, OutputIt begin, OutputIt end)
{ {
return PadderImpl::ComputeUnpad(begin, end); return padder.ComputeUnpad(begin, end);
} }
TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest) TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest)
@@ -357,7 +358,8 @@ TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest)
{ {
std::array<uint8_t, 5> data = { 0x05, 0x05, 0x05, 0x05, 0x05 }; std::array<uint8_t, 5> data = { 0x05, 0x05, 0x05, 0x05, 0x05 };
auto result = ComputeUnpadGeneric<PadderPkcs7>(data.begin(), data.end()); const PadderPkcs7 padder;
auto result = ComputeUnpadGeneric(padder, data.begin(), data.end());
ASSERT_TRUE(result.IsOkay_); ASSERT_TRUE(result.IsOkay_);
ASSERT_EQ(5, result.PadSize_); ASSERT_EQ(5, result.PadSize_);
-78
View File
@@ -3,7 +3,6 @@
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
#include <cstddef> #include <cstddef>
#include <utility>
#include "Service/SeArray.hpp" #include "Service/SeArray.hpp"
@@ -291,80 +290,3 @@ TEST(SeArrayTests, CopyAssignTest)
ASSERT_EQ(0, arr1[4]); ASSERT_EQ(0, arr1[4]);
} }
} }
TEST(SeArrayTests, MoveAssignTest)
{
{
SeArray<uint8_t, 2> arr1;
SeArray<uint8_t, 2> arr2;
arr2[0] = 0xaa;
arr2[1] = 0xbb;
arr1 = std::move(arr2);
ASSERT_EQ(0xaa, arr1[0]);
ASSERT_EQ(0xbb, arr1[1]);
ASSERT_EQ(0, arr2[0]);
ASSERT_EQ(0, arr2[1]);
}
{
SeArray<int32_t, 5> arr1;
arr1[0] = 0x33;
arr1[1] = 0x44;
arr1[2] = 0x55;
arr1[3] = 0x66;
arr1[4] = 0x77;
SeArray<int32_t, 5> arr2;
arr1 = std::move(arr2);
ASSERT_EQ(0, arr1[0]);
ASSERT_EQ(0, arr1[1]);
ASSERT_EQ(0, arr1[2]);
ASSERT_EQ(0, arr1[3]);
ASSERT_EQ(0, arr1[4]);
ASSERT_EQ(0, arr2[0]);
ASSERT_EQ(0, arr2[1]);
ASSERT_EQ(0, arr2[2]);
ASSERT_EQ(0, arr2[3]);
ASSERT_EQ(0, arr2[4]);
}
{
SeArray<int32_t, 5> arr1;
arr1[0] = 0x33;
arr1[1] = 0x44;
arr1[2] = 0x55;
arr1[3] = 0x66;
arr1[4] = 0x77;
arr1 = std::move(arr1);
ASSERT_EQ(0x33, arr1[0]);
ASSERT_EQ(0x44, arr1[1]);
ASSERT_EQ(0x55, arr1[2]);
ASSERT_EQ(0x66, arr1[3]);
ASSERT_EQ(0x77, arr1[4]);
}
}
TEST(SeArrayTests, MoveConstructTest)
{
{
SeArray<int32_t, 2> arr1;
arr1[0] = 0x11;
arr1[1] = 0x22;
SeArray<int32_t, 2> arr2(std::move(arr1));
ASSERT_EQ(0x11, arr2[0]);
ASSERT_EQ(0x22, arr2[1]);
ASSERT_EQ(0, arr1[0]);
ASSERT_EQ(0, arr1[1]);
}
}