aws-crt-cpp
C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++.
Hash.h
Go to the documentation of this file.
1#pragma once
6#include <aws/crt/Exports.h>
7#include <aws/crt/Types.h>
8
9#include <aws/cal/hash.h>
10
11struct aws_hash;
12namespace Aws
13{
14 namespace Crt
15 {
16 namespace Crypto
17 {
18 static const size_t SHA256_DIGEST_SIZE = 32;
19 static const size_t MD5_DIGEST_SIZE = 16;
20
28 Allocator *allocator,
29 const ByteCursor &input,
30 ByteBuf &output,
31 size_t truncateTo = 0) noexcept;
32
40 ComputeSHA256(const ByteCursor &input, ByteBuf &output, size_t truncateTo = 0) noexcept;
41
49 Allocator *allocator,
50 const ByteCursor &input,
51 ByteBuf &output,
52 size_t truncateTo = 0) noexcept;
53
60 bool AWS_CRT_CPP_API ComputeMD5(const ByteCursor &input, ByteBuf &output, size_t truncateTo = 0) noexcept;
61
68 {
69 public:
70 ~Hash();
71 Hash(const Hash &) = delete;
72 Hash &operator=(const Hash &) = delete;
73 Hash(Hash &&toMove);
74 Hash &operator=(Hash &&toMove);
75
79 inline operator bool() const noexcept { return m_good; }
80
84 inline int LastError() const noexcept { return m_lastError; }
85
89 static Hash CreateSHA256(Allocator *allocator = g_allocator) noexcept;
90
94 static Hash CreateMD5(Allocator *allocator = g_allocator) noexcept;
95
100 bool Update(const ByteCursor &toHash) noexcept;
101
108 bool Digest(ByteBuf &output, size_t truncateTo = 0) noexcept;
109
110 private:
111 Hash(aws_hash *hash) noexcept;
112 Hash() = delete;
113
114 aws_hash *m_hash;
115 bool m_good;
116 int m_lastError;
117 };
118
126 {
127 public:
128 virtual ~ByoHash();
129
134 aws_hash *SeatForCInterop(const std::shared_ptr<ByoHash> &selfRef);
135
136 protected:
137 ByoHash(size_t digestSize, Allocator *allocator = g_allocator);
138
144 virtual bool UpdateInternal(const ByteCursor &toHash) noexcept = 0;
145
152 virtual bool DigestInternal(ByteBuf &output, size_t truncateTo = 0) noexcept = 0;
153
154 private:
155 static void s_Destroy(struct aws_hash *hash);
156 static int s_Update(struct aws_hash *hash, const struct aws_byte_cursor *buf);
157 static int s_Finalize(struct aws_hash *hash, struct aws_byte_buf *out);
158
159 static aws_hash_vtable s_Vtable;
160 aws_hash m_hashValue;
161 std::shared_ptr<ByoHash> m_selfReference;
162 };
163
164 using CreateHashCallback = std::function<std::shared_ptr<ByoHash>(size_t digestSize, Allocator *)>;
165
166 } // namespace Crypto
167 } // namespace Crt
168} // namespace Aws
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Definition: Hash.h:126
virtual bool DigestInternal(ByteBuf &output, size_t truncateTo=0) noexcept=0
virtual bool UpdateInternal(const ByteCursor &toHash) noexcept=0
Definition: Hash.h:68
int LastError() const noexcept
Definition: Hash.h:84
Hash & operator=(const Hash &)=delete
Hash(const Hash &)=delete
bool AWS_CRT_CPP_API ComputeMD5(Allocator *allocator, const ByteCursor &input, ByteBuf &output, size_t truncateTo=0) noexcept
Definition: Hash.cpp:29
std::function< std::shared_ptr< ByoHash >(size_t digestSize, Allocator *)> CreateHashCallback
Definition: Hash.h:164
static const size_t SHA256_DIGEST_SIZE
Definition: Hash.h:18
bool AWS_CRT_CPP_API ComputeSHA256(Allocator *allocator, const ByteCursor &input, ByteBuf &output, size_t truncateTo=0) noexcept
Definition: Hash.cpp:15
static const size_t MD5_DIGEST_SIZE
Definition: Hash.h:19
aws_byte_cursor ByteCursor
Definition: Types.h:33
aws_allocator Allocator
Definition: StlAllocator.h:17
AWS_CRT_CPP_API Allocator * g_allocator
Definition: Api.cpp:21
aws_byte_buf ByteBuf
Definition: Types.h:32
Definition: Api.h:17
Definition: StringView.h:846