ThingsBoard Client SDK 0.16.0
Client SDK to connect with ThingsBoard IoT Platform from IoT devices (Arduino, Espressif, etc.)
Loading...
Searching...
No Matches
HashGenerator.h
Go to the documentation of this file.
1#ifndef Hash_Generator_h
2#define Hash_Generator_h
3
4// Local includes.
5#include "Configuration.h"
6
7// Library includes.
8#if THINGSBOARD_USE_MBED_TLS
9#include <mbedtls/md.h>
10#else
11#include <Seeed_mbedtls.h>
12#endif // THINGSBOARD_USE_MBED_TLS
13#include <stdint.h>
14#include <stddef.h>
15
16// Maximum size of the hash string representation, consists of size required for byte representation of the hash * 2 because every byte is 2 hex characters + 1 for null termination character
17size_t constexpr MAX_STRING_HASH_SIZE = (MBEDTLS_MD_MAX_SIZE * 2U) + 1U;
18
19
29 public:
34 {
36 };
37
39 HashGenerator(void) = default;
40
44 HashGenerator(HashGenerator const & other) = delete;
45
49 void operator=(HashGenerator const & other) = delete;
50
52 ~HashGenerator(void);
53
57 bool start(mbedtls_md_type_t const & type);
58
64 bool update(uint8_t const * data, size_t const & length);
65
70
71 private:
74 void free();
75
81 size_t mbedtls_type_to_size(mbedtls_md_type_t const & type);
82
83 size_t m_size = {}; // Actual size in bytes, depend on the mbedtls_md_type_t given in the start method
84 mbedtls_md_context_t m_ctx = {}; // Context used to access the already written bytes and update them latter
85};
86
87#endif // Hash_Generator_h
size_t constexpr MAX_STRING_HASH_SIZE
Definition: HashGenerator.h:17
Wrapper class which allows generating a hash of a given type from any arbitrary byte payload,...
Definition: HashGenerator.h:28
~HashGenerator(void)
Destructor.
Definition: HashGenerator.cpp:7
bool start(mbedtls_md_type_t const &type)
Starts the hashing process.
Definition: HashGenerator.cpp:11
bool update(uint8_t const *data, size_t const &length)
Update the current hash value with new data.
Definition: HashGenerator.cpp:24
HashGenerator(void)=default
Constructor.
HashGenerator(HashGenerator const &other)=delete
Deleted copy constructor.
HashString finish()
Calculates the final hash string representation and stops the hash calculation no further calls to up...
Definition: HashGenerator.cpp:28
void operator=(HashGenerator const &other)=delete
Deleted copy assignment operator.
Wrapper class for the char array that is big enough to hold the string representation of every possib...
Definition: HashGenerator.h:34
char hash[MAX_STRING_HASH_SIZE]
Definition: HashGenerator.h:35