Introduce Block::Encryptor<> CRTP base class.
Inherit DesEncryptor from it.
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include "Service/ChaosException.hpp"
|
||||
#include "Service/SeArray.hpp"
|
||||
|
||||
#include "Cipher/Block/Encryptor.hpp"
|
||||
|
||||
namespace Chaos::Cipher::Block::Des::Inner_
|
||||
{
|
||||
|
||||
@@ -221,7 +223,7 @@ public:
|
||||
Inner_::RawKey Key_;
|
||||
};
|
||||
|
||||
class DesEncryptor
|
||||
class DesEncryptor : public Encryptor<DesEncryptor>
|
||||
{
|
||||
public:
|
||||
DesEncryptor(const Key & key)
|
||||
|
||||
40
Chaos/Cipher/Block/Encryptor.hpp
Normal file
40
Chaos/Cipher/Block/Encryptor.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef CHAOS_CIPHER_BLOCK_ENCRYPTOR_HPP
|
||||
#define CHAOS_CIPHER_BLOCK_ENCRYPTOR_HPP
|
||||
|
||||
namespace Chaos::Cipher::Block
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
class Encryptor
|
||||
{
|
||||
public:
|
||||
template<typename OutputIt, typename InputIt>
|
||||
void EncryptBlock(OutputIt out, InputIt inBegin, InputIt inEnd)
|
||||
{
|
||||
Impl().EncryptBlock(out, inBegin, inEnd);
|
||||
}
|
||||
|
||||
template<typename Block>
|
||||
auto EncryptBlock(Block block)
|
||||
{
|
||||
return Impl().EncryptBlock(block);
|
||||
}
|
||||
|
||||
protected:
|
||||
Encryptor() = default;
|
||||
|
||||
private:
|
||||
const T & Impl() const
|
||||
{
|
||||
return static_cast<const T &>(*this);
|
||||
}
|
||||
|
||||
T & Impl()
|
||||
{
|
||||
return static_cast<T &>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Chaos::Cipher::Block
|
||||
|
||||
#endif // CHAOS_CIPHER_BLOCK_ENCRYPTOR_HPP
|
||||
Reference in New Issue
Block a user