Files
chaos/Chaos/Padding/PadderPkcs7.hpp
hashlag 797a5428cc
All checks were successful
Chaos Ci / test-and-benchmark (push) Successful in 1m59s
Add Padder<>. A CRTP base for padding algorithms.
2026-02-08 23:44:51 +03:00

39 lines
839 B
C++

#ifndef CHAOS_PADDING_PADDERPKCS7_HPP
#define CHAOS_PADDING_PADDERPKCS7_HPP
#include <cstdint>
#include <iterator>
#include <limits>
#include "Padding/Padder.hpp"
#include "Service/ChaosException.hpp"
namespace Chaos::Padding
{
class PadderPkcs7 : public Padder<PadderPkcs7>
{
public:
template<typename OutputIt>
static void Pad(OutputIt begin, OutputIt end)
{
auto dist = std::distance(begin, end);
if (dist >= 0 && dist <= std::numeric_limits<uint8_t>::max())
{
for (OutputIt it = begin; it != end; ++it)
{
*it = static_cast<uint8_t>(dist);
}
}
else
{
throw Service::ChaosException("PadPkcs7::Pad(): invalid range");
}
}
};
} // namespace Chaos::Padding
#endif // CHAOS_PADDING_PADDERPKCS7_HPP