AWS IoT Device SDK C++ v2: crt/aws-crt-cpp/include/aws/crt/crypto/Hash.h Source File

AWS IoT Device SDK C++ v2 1.14.0 AWS IoT Device SDK C++ v2

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
27 bool AWS_CRT_CPP_API ComputeSHA256(
28 Allocator *allocator,
29 const ByteCursor &input,
30 ByteBuf &output,
31 size_t truncateTo = 0) noexcept;
32
39 bool AWS_CRT_CPP_API
40 ComputeSHA256(const ByteCursor &input, ByteBuf &output, size_t truncateTo = 0) noexcept;
41
48 bool AWS_CRT_CPP_API ComputeMD5(
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
67 class AWS_CRT_CPP_API Hash final
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
125 class AWS_CRT_CPP_API ByoHash
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
Types.h
Aws::Crt::Crypto::ByoHash
Definition: Hash.h:126
Aws::Crt::Crypto::ByoHash::DigestInternal
virtual bool DigestInternal(ByteBuf &output, size_t truncateTo=0) noexcept=0
Aws::Crt::Crypto::ByoHash::UpdateInternal
virtual bool UpdateInternal(const ByteCursor &toHash) noexcept=0
Aws::Crt::Crypto::Hash
Definition: Hash.h:68
Aws::Crt::Crypto::Hash::LastError
int LastError() const noexcept
Definition: Hash.h:84
Aws::Crt::Crypto::Hash::operator=
Hash & operator=(const Hash &)=delete
Aws::Crt::Crypto::Hash::Hash
Hash(const Hash &)=delete
Exports.h
AWS_CRT_CPP_API
#define AWS_CRT_CPP_API
Definition: Exports.h:37
Aws::Crt::Crypto::ComputeMD5
bool AWS_CRT_CPP_API ComputeMD5(Allocator *allocator, const ByteCursor &input, ByteBuf &output, size_t truncateTo=0) noexcept
Definition: Hash.cpp:29
Aws::Crt::Crypto::CreateHashCallback
std::function< std::shared_ptr< ByoHash >(size_t digestSize, Allocator *)> CreateHashCallback
Definition: Hash.h:164
Aws::Crt::Crypto::SHA256_DIGEST_SIZE
static const size_t SHA256_DIGEST_SIZE
Definition: Hash.h:18
Aws::Crt::Crypto::ComputeSHA256
bool AWS_CRT_CPP_API ComputeSHA256(Allocator *allocator, const ByteCursor &input, ByteBuf &output, size_t truncateTo=0) noexcept
Definition: Hash.cpp:15
Aws::Crt::Crypto::MD5_DIGEST_SIZE
static const size_t MD5_DIGEST_SIZE
Definition: Hash.h:19
Aws::Crt::ByteCursor
aws_byte_cursor ByteCursor
Definition: Types.h:33
Aws::Crt::Allocator
aws_allocator Allocator
Definition: StlAllocator.h:17
Aws::Crt::g_allocator
AWS_CRT_CPP_API Allocator * g_allocator
Definition: Api.cpp:21
Aws::Crt::ByteBuf
aws_byte_buf ByteBuf
Definition: Types.h:32
Aws
Definition: Api.h:17
std
Definition: StringView.h:851