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::Hasher {
17 enum class Type {
18 Blake2b,
19 Blake2s,
20 SHA3_256,
21 SHA3_512,
22 SHA256,
23 SHA512,
24 };
25
30 class STORMBYTE_CRYPTO_PUBLIC Generic: public StormByte::Clonable<Generic> {
31 public:
36 Generic(const Generic& other) = default;
37
42 Generic(Generic&& other) noexcept = default;
43
47 virtual ~Generic() noexcept = default;
48
54 Generic& operator=(const Generic& other) = default;
55
61 Generic& operator=(Generic&& other) noexcept = default;
62
69 inline bool Hash(std::span<const std::byte> input, Buffer::WriteOnly& output) const noexcept {
70 return DoHash(input, output);
71 }
72
79 inline bool Hash(const Buffer::ReadOnly& input, Buffer::WriteOnly& output) const noexcept {
80 return DoHash(const_cast<Buffer::ReadOnly&>(input), output, ReadMode::Copy);
81 }
82
89 inline bool Hash(Buffer::ReadOnly& input, Buffer::WriteOnly& output) const noexcept {
90 return DoHash(input, output, ReadMode::Move);
91 }
92
99 inline Buffer::Consumer Hash(Buffer::Consumer consumer, ReadMode mode = ReadMode::Move) const noexcept {
100 return DoHash(consumer, mode);
101 }
102
107 inline enum Type Type() const noexcept {
108 return m_type;
109 }
110
111 protected:
112 enum Type m_type;
113
118 inline Generic(enum Type type):
119 m_type(type) {}
120
121 private:
129 bool DoHash(Buffer::ReadOnly& input, Buffer::WriteOnly& output, ReadMode mode) const noexcept;
130
138 virtual bool DoHash(std::span<const std::byte> input, Buffer::WriteOnly& output) const noexcept = 0;
139
146 virtual Buffer::Consumer DoHash(Buffer::Consumer consumer, ReadMode mode) const noexcept = 0;
147 };
148
154 STORMBYTE_CRYPTO_PUBLIC Generic::PointerType Create(Type type) noexcept;
155}
A generic hasher class.
Definition generic.hxx:30
bool Hash(const Buffer::ReadOnly &input, Buffer::WriteOnly &output) const noexcept
Hash data from input buffer to output buffer.
Definition generic.hxx:79
Generic(Generic &&other) noexcept=default
Move constructor.
enum Type m_type
The type of hasher.
Definition generic.hxx:112
enum Type Type() const noexcept
Gets the type of hasher.
Definition generic.hxx:107
Buffer::Consumer Hash(Buffer::Consumer consumer, ReadMode mode=ReadMode::Move) const noexcept
Hash data from a Consumer buffer.
Definition generic.hxx:99
bool Hash(Buffer::ReadOnly &input, Buffer::WriteOnly &output) const noexcept
Hash data from input buffer to output buffer, moving the input data.
Definition generic.hxx:89
Generic(enum Type type)
Constructor.
Definition generic.hxx:118
virtual ~Generic() noexcept=default
Virtual destructor.
Generic(const Generic &other)=default
Copy constructor.