Add PKCS#7 padding implementation.
All checks were successful
Chaos Ci / test-and-benchmark (push) Successful in 1m58s
All checks were successful
Chaos Ci / test-and-benchmark (push) Successful in 1m58s
This commit is contained in:
37
Chaos/Padding/PadPkcs7.hpp
Normal file
37
Chaos/Padding/PadPkcs7.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef CHAOS_PADDING_PADPKCS7_HPP
|
||||
#define CHAOS_PADDING_PADPKCS7_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
|
||||
#include "Service/ChaosException.hpp"
|
||||
|
||||
namespace Chaos::Padding
|
||||
{
|
||||
|
||||
class PadPkcs7
|
||||
{
|
||||
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_PADPKCS7_HPP
|
||||
Reference in New Issue
Block a user