ESPHome  2024.11.0
hmac_md5.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/defines.h"
4 #ifdef USE_MD5
6 #include <string>
7 
8 namespace esphome {
9 namespace hmac_md5 {
10 
11 class HmacMD5 {
12  public:
13  HmacMD5() = default;
14  ~HmacMD5() = default;
15 
17  void init(const uint8_t *key, size_t len);
18  void init(const char *key, size_t len) { this->init((const uint8_t *) key, len); }
19  void init(const std::string &key) { this->init(key.c_str(), key.length()); }
20 
22  void add(const uint8_t *data, size_t len);
23  void add(const char *data, size_t len) { this->add((const uint8_t *) data, len); }
24 
26  void calculate();
27 
30  void get_bytes(uint8_t *output);
31 
34  void get_hex(char *output);
35 
37  bool equals_bytes(const uint8_t *expected);
38 
40  bool equals_hex(const char *expected);
41 
42  protected:
45 };
46 
47 } // namespace hmac_md5
48 } // namespace esphome
49 #endif
void init(const std::string &key)
Definition: hmac_md5.h:19
md5::MD5Digest ohash_
Definition: hmac_md5.h:44
void init(const uint8_t *key, size_t len)
Initialize a new MD5 digest computation.
Definition: hmac_md5.cpp:9
void get_bytes(uint8_t *output)
Retrieve the HMAC-MD5 digest as bytes.
Definition: hmac_md5.cpp:48
void init(const char *key, size_t len)
Definition: hmac_md5.h:18
bool equals_bytes(const uint8_t *expected)
Compare the digest against a provided byte-encoded digest (16 bytes).
Definition: hmac_md5.cpp:52
bool equals_hex(const char *expected)
Compare the digest against a provided hex-encoded digest (32 bytes).
Definition: hmac_md5.cpp:54
void add(const uint8_t *data, size_t len)
Add bytes of data for the digest.
Definition: hmac_md5.cpp:36
md5::MD5Digest ihash_
Definition: hmac_md5.h:43
void add(const char *data, size_t len)
Definition: hmac_md5.h:23
void calculate()
Compute the digest, based on the provided data.
Definition: hmac_md5.cpp:38
std::string size_t len
Definition: helpers.h:293
void get_hex(char *output)
Retrieve the HMAC-MD5 digest as hex characters.
Definition: hmac_md5.cpp:50
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7