25#include "../../abi/string.hpp"
26#include "../../rational.hpp"
35namespace essence::crypto::abstract {
44 explicit chunk_processor(T&& value) : wrapper_{std::make_unique<wrapper<T>>(std::forward<T>(value))} {}
51 return wrapper_->transformer();
59 return wrapper_->cipher_name();
67 return wrapper_->buffer_size();
75 return wrapper_->extra_size();
84 return wrapper_->size_factor();
99 void update(std::span<const std::byte> input, std::span<std::byte>& output)
const {
100 wrapper_->update(input, output);
107 void finalize(std::span<std::byte>& output)
const {
108 wrapper_->finalize(output);
113 virtual ~base() =
default;
114 virtual bool transformer() = 0;
115 virtual abi::string cipher_name() = 0;
116 virtual std::size_t buffer_size() = 0;
117 virtual std::size_t extra_size() = 0;
119 virtual void init() = 0;
120 virtual void update(std::span<const std::byte> input, std::span<std::byte>& output) = 0;
121 virtual void finalize(std::span<std::byte>& output) = 0;
124 template <
typename T>
125 class wrapper final :
public base {
127 template <std::convertible_to<T> U>
128 explicit wrapper(U&& value) : value_{std::forward<U>(value)} {}
130 bool transformer()
override {
131 return value_.transformer();
134 abi::string cipher_name()
override {
135 return value_.cipher_name();
138 std::size_t buffer_size()
override {
139 return value_.buffer_size();
142 std::size_t extra_size()
override {
143 return value_.extra_size();
146 rational size_factor()
override {
147 return value_.size_factor();
150 void init()
override {
154 void update(std::span<const std::byte> input, std::span<std::byte>& output)
override {
155 value_.update(input, output);
158 void finalize(std::span<std::byte>& output)
override {
159 value_.finalize(output);
166 std::unique_ptr<base> wrapper_;
Provides a uniform interface for processing crypto chunks.
Definition chunk_processor.hpp:40
abi::string cipher_name() const
Gets the name of the cipher.
Definition chunk_processor.hpp:58
void update(std::span< const std::byte > input, std::span< std::byte > &output) const
Processes a memory chunk.
Definition chunk_processor.hpp:99
rational size_factor() const
Gets the factor to be multiplied to the input buffer size and the result is the size of the output bu...
Definition chunk_processor.hpp:83
bool transformer() const
Indicates whether this is a forward transformer.
Definition chunk_processor.hpp:50
std::size_t buffer_size() const
Gets the size of the input buffer.
Definition chunk_processor.hpp:66
std::size_t extra_size() const
Gets the extra size of the output buffer.
Definition chunk_processor.hpp:74
void finalize(std::span< std::byte > &output) const
Gets the final chunk.
Definition chunk_processor.hpp:107
void init() const
Initializes the processor.
Definition chunk_processor.hpp:90
Represents a rational number consisting of its corresponding numerator and denominator.
Definition rational.hpp:53