ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
hmac_md5.h
Go to the documentation of this file.
1#pragma once
2
4#ifdef USE_MD5
6#include <string>
7
8namespace esphome::hmac_md5 {
9
10class HmacMD5 {
11 public:
12 HmacMD5() = default;
13 ~HmacMD5() = default;
14
16 void init(const uint8_t *key, size_t len);
17 void init(const char *key, size_t len) { this->init((const uint8_t *) key, len); }
18 void init(const std::string &key) { this->init(key.c_str(), key.length()); }
19
21 void add(const uint8_t *data, size_t len);
22 void add(const char *data, size_t len) { this->add((const uint8_t *) data, len); }
23
25 void calculate();
26
29 void get_bytes(uint8_t *output);
30
33 void get_hex(char *output);
34
36 bool equals_bytes(const uint8_t *expected);
37
39 bool equals_hex(const char *expected);
40
41 protected:
44};
45
46} // namespace esphome::hmac_md5
47
48#endif
bool equals_hex(const char *expected)
Compare the digest against a provided hex-encoded digest (32 bytes).
Definition hmac_md5.cpp:53
void init(const uint8_t *key, size_t len)
Initialize a new MD5 digest computation.
Definition hmac_md5.cpp:8
void init(const char *key, size_t len)
Definition hmac_md5.h:17
void calculate()
Compute the digest, based on the provided data.
Definition hmac_md5.cpp:37
void init(const std::string &key)
Definition hmac_md5.h:18
void add(const char *data, size_t len)
Definition hmac_md5.h:22
md5::MD5Digest ihash_
Definition hmac_md5.h:42
md5::MD5Digest ohash_
Definition hmac_md5.h:43
void get_hex(char *output)
Retrieve the HMAC-MD5 digest as hex characters.
Definition hmac_md5.cpp:49
void add(const uint8_t *data, size_t len)
Add bytes of data for the digest.
Definition hmac_md5.cpp:35
bool equals_bytes(const uint8_t *expected)
Compare the digest against a provided byte-encoded digest (16 bytes).
Definition hmac_md5.cpp:51
void get_bytes(uint8_t *output)
Retrieve the HMAC-MD5 digest as bytes.
Definition hmac_md5.cpp:47
std::string size_t len