Add Padder<>. A CRTP base for padding algorithms.
All checks were successful
Chaos Ci / test-and-benchmark (push) Successful in 1m59s
All checks were successful
Chaos Ci / test-and-benchmark (push) Successful in 1m59s
This commit is contained in:
34
Chaos/Padding/Padder.hpp
Normal file
34
Chaos/Padding/Padder.hpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef CHAOS_PADDING_PADDER_HPP
|
||||||
|
#define CHAOS_PADDING_PADDER_HPP
|
||||||
|
|
||||||
|
namespace Chaos::Padding
|
||||||
|
{
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Padder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template<typename OutputIt>
|
||||||
|
void Pad(OutputIt begin, OutputIt end) const
|
||||||
|
{
|
||||||
|
Impl().Pad(begin, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Padder() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const T & Impl() const
|
||||||
|
{
|
||||||
|
return static_cast<const T &>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
T & Impl()
|
||||||
|
{
|
||||||
|
return static_cast<T &>(*this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Chaos::Padding
|
||||||
|
|
||||||
|
#endif // CHAOS_PADDING_PADDER_HPP
|
||||||
@@ -5,12 +5,13 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include "Padding/Padder.hpp"
|
||||||
#include "Service/ChaosException.hpp"
|
#include "Service/ChaosException.hpp"
|
||||||
|
|
||||||
namespace Chaos::Padding
|
namespace Chaos::Padding
|
||||||
{
|
{
|
||||||
|
|
||||||
class PadderPkcs7
|
class PadderPkcs7 : public Padder<PadderPkcs7>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<typename OutputIt>
|
template<typename OutputIt>
|
||||||
|
|||||||
@@ -119,3 +119,25 @@ TEST(PadPkcs7Tests, PadOutIteratorUsageTest)
|
|||||||
ASSERT_EQ(expected, fact);
|
ASSERT_EQ(expected, fact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Impl, typename OutputIt>
|
||||||
|
void PadThroughBase(const Padder<Impl> & padder, OutputIt begin, OutputIt end)
|
||||||
|
{
|
||||||
|
padder.Pad(begin, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PadPkcs7Tests, PadThroughBaseTest)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::array<uint8_t, 5> fact = {};
|
||||||
|
std::array<uint8_t, 5> expected =
|
||||||
|
{
|
||||||
|
0x05, 0x05, 0x05, 0x05, 0x05
|
||||||
|
};
|
||||||
|
|
||||||
|
const PadderPkcs7 padder;
|
||||||
|
PadThroughBase(padder, fact.begin(), fact.end());
|
||||||
|
|
||||||
|
ASSERT_EQ(expected, fact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user