diff --git a/Chaos/Padding/Padder.hpp b/Chaos/Padding/Padder.hpp new file mode 100644 index 0000000..2f75e6e --- /dev/null +++ b/Chaos/Padding/Padder.hpp @@ -0,0 +1,34 @@ +#ifndef CHAOS_PADDING_PADDER_HPP +#define CHAOS_PADDING_PADDER_HPP + +namespace Chaos::Padding +{ + +template +class Padder +{ +public: + template + void Pad(OutputIt begin, OutputIt end) const + { + Impl().Pad(begin, end); + } + +protected: + Padder() = default; + +private: + const T & Impl() const + { + return static_cast(*this); + } + + T & Impl() + { + return static_cast(*this); + } +}; + +} // namespace Chaos::Padding + +#endif // CHAOS_PADDING_PADDER_HPP diff --git a/Chaos/Padding/PadderPkcs7.hpp b/Chaos/Padding/PadderPkcs7.hpp index e35d891..9cbe53c 100644 --- a/Chaos/Padding/PadderPkcs7.hpp +++ b/Chaos/Padding/PadderPkcs7.hpp @@ -5,12 +5,13 @@ #include #include +#include "Padding/Padder.hpp" #include "Service/ChaosException.hpp" namespace Chaos::Padding { -class PadderPkcs7 +class PadderPkcs7 : public Padder { public: template diff --git a/ChaosTests/Padding/PadderPkcs7Tests.cpp b/ChaosTests/Padding/PadderPkcs7Tests.cpp index bfbcdaf..874a704 100644 --- a/ChaosTests/Padding/PadderPkcs7Tests.cpp +++ b/ChaosTests/Padding/PadderPkcs7Tests.cpp @@ -119,3 +119,25 @@ TEST(PadPkcs7Tests, PadOutIteratorUsageTest) ASSERT_EQ(expected, fact); } } + +template +void PadThroughBase(const Padder & padder, OutputIt begin, OutputIt end) +{ + padder.Pad(begin, end); +} + +TEST(PadPkcs7Tests, PadThroughBaseTest) +{ + { + std::array fact = {}; + std::array expected = + { + 0x05, 0x05, 0x05, 0x05, 0x05 + }; + + const PadderPkcs7 padder; + PadThroughBase(padder, fact.begin(), fact.end()); + + ASSERT_EQ(expected, fact); + } +}