StormByte C++ Library: Crypto module 0.0.9999
StormByte-Crypto is a StormByte library module for handling cryptographic operations
Loading...
Searching...
No Matches
generic.hxx
1#pragma once
2
3#include <StormByte/buffer/consumer.hxx>
4#include <StormByte/clonable.hxx>
5#include <StormByte/crypto/typedefs.hxx>
6#include <StormByte/crypto/visibility.h>
7
12namespace StormByte::Crypto::Compressor {
17 enum class Type {
18 Bzip2,
19 Zlib
20 };
21
26 class STORMBYTE_CRYPTO_PUBLIC Generic: public StormByte::Clonable<Generic> {
27 public:
32 Generic(const Generic& other) = default;
33
38 Generic(Generic&& other) noexcept = default;
39
43 virtual ~Generic() noexcept = default;
44
50 Generic& operator=(const Generic& other) = default;
51
57 Generic& operator=(Generic&& other) noexcept = default;
58
65 inline bool Compress(const std::span<const std::byte> input, Buffer::WriteOnly& output) const noexcept {
66 return DoCompress(input, output);
67 }
68
75 inline bool Compress(const Buffer::ReadOnly& input, Buffer::WriteOnly& output) const noexcept {
76 return DoCompress(const_cast<Buffer::ReadOnly&>(input), output, ReadMode::Copy);
77 }
78
85 inline bool Compress(Buffer::ReadOnly& input, Buffer::WriteOnly& output) const noexcept {
86 return DoCompress(input, output, ReadMode::Move);
87 }
88
95 inline Buffer::Consumer Compress(Buffer::Consumer consumer, ReadMode mode = ReadMode::Move) const noexcept {
96 return DoCompress(consumer, mode);
97 }
98
105 inline bool Decompress(const std::span<const std::byte> input, Buffer::WriteOnly& output) const noexcept {
106 return DoDecompress(input, output);
107 }
108
115 inline bool Decompress(const Buffer::ReadOnly& input, Buffer::WriteOnly& output) const noexcept {
116 return DoDecompress(const_cast<Buffer::ReadOnly&>(input), output, ReadMode::Copy);
117 }
118
125 inline bool Decompress(Buffer::ReadOnly& input, Buffer::WriteOnly& output) const noexcept {
126 return DoDecompress(input, output, ReadMode::Move);
127 }
128
135 inline Buffer::Consumer Decompress(Buffer::Consumer consumer, ReadMode mode = ReadMode::Move) const noexcept {
136 return DoDecompress(consumer, mode);
137 }
138
143 unsigned short Level() const noexcept {
144 return m_level;
145 }
146
151 inline enum Type Type() const noexcept {
152 return m_type;
153 }
154
155 protected:
156 enum Type m_type;
157 unsigned short m_level = 0;
158
163 inline Generic(enum Type type, unsigned short level = 5):
164 m_type(type), m_level(level) {}
165
166 private:
174 virtual bool DoCompress(std::span<const std::byte> input, Buffer::WriteOnly& output) const noexcept = 0;
175
183 bool DoCompress(Buffer::ReadOnly& input, Buffer::WriteOnly& output, ReadMode mode) const noexcept;
184
191 virtual Buffer::Consumer DoCompress(Buffer::Consumer consumer, ReadMode mode) const noexcept = 0;
192
200 virtual bool DoDecompress(std::span<const std::byte> input, Buffer::WriteOnly& output) const noexcept = 0;
201
209 bool DoDecompress(Buffer::ReadOnly& input, Buffer::WriteOnly& output, ReadMode mode) const noexcept;
210
217 virtual Buffer::Consumer DoDecompress(Buffer::Consumer consumer, ReadMode mode) const noexcept = 0;
218 };
219
226 STORMBYTE_CRYPTO_PUBLIC Generic::PointerType Create(Type type, unsigned short level) noexcept;
227}
A generic compressor class.
Definition generic.hxx:26
virtual ~Generic() noexcept=default
Virtual destructor.
enum Type Type() const noexcept
Gets the type of compressor.
Definition generic.hxx:151
bool Decompress(Buffer::ReadOnly &input, Buffer::WriteOnly &output) const noexcept
Decompress data from input buffer to output buffer, moving the input data.
Definition generic.hxx:125
Buffer::Consumer Compress(Buffer::Consumer consumer, ReadMode mode=ReadMode::Move) const noexcept
Compress data from a Consumer buffer.
Definition generic.hxx:95
Buffer::Consumer Decompress(Buffer::Consumer consumer, ReadMode mode=ReadMode::Move) const noexcept
Decompress data from a Consumer buffer.
Definition generic.hxx:135
bool Decompress(const std::span< const std::byte > input, Buffer::WriteOnly &output) const noexcept
Decompress data from input buffer to output buffer.
Definition generic.hxx:105
Generic(Generic &&other) noexcept=default
Move constructor.
Generic(const Generic &other)=default
Copy constructor.
unsigned short Level() const noexcept
Gets the compression level.
Definition generic.hxx:143
bool Compress(const Buffer::ReadOnly &input, Buffer::WriteOnly &output) const noexcept
Compress data from input buffer to output buffer.
Definition generic.hxx:75
bool Decompress(const Buffer::ReadOnly &input, Buffer::WriteOnly &output) const noexcept
Decompress data from input buffer to output buffer.
Definition generic.hxx:115
enum Type m_type
The type of compressor.
Definition generic.hxx:156
Generic(enum Type type, unsigned short level=5)
Constructor.
Definition generic.hxx:163
bool Compress(Buffer::ReadOnly &input, Buffer::WriteOnly &output) const noexcept
Compress data from input buffer to output buffer, moving the input data.
Definition generic.hxx:85