ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
md5.h
Go to the documentation of this file.
1#pragma once
2
4#ifdef USE_MD5
5
6#ifdef USE_ESP32
7#include "esp_rom_md5.h"
8#define MD5_CTX_TYPE md5_context_t
9#endif
10
11#if defined(USE_ARDUINO) && defined(USE_ESP8266)
12#include <md5.h>
13#define MD5_CTX_TYPE md5_context_t
14#endif
15
16#ifdef USE_RP2040
17#include <MD5Builder.h>
18#define MD5_CTX_TYPE br_md5_context
19#endif
20
21#if defined(USE_LIBRETINY)
22#include <MD5.h>
23#define MD5_CTX_TYPE LT_MD5_CTX_T
24#endif
25
26namespace esphome {
27namespace md5 {
28
29class MD5Digest {
30 public:
31 MD5Digest() = default;
32 ~MD5Digest() = default;
33
35 void init();
36
38 void add(const uint8_t *data, size_t len);
39 void add(const char *data, size_t len) { this->add((const uint8_t *) data, len); }
40
42 void calculate();
43
46 void get_bytes(uint8_t *output);
47
50 void get_hex(char *output);
51
53 bool equals_bytes(const uint8_t *expected);
54
56 bool equals_hex(const char *expected);
57
58 protected:
59 MD5_CTX_TYPE ctx_{};
60 uint8_t digest_[16];
61};
62
63} // namespace md5
64} // namespace esphome
65#endif
bool equals_hex(const char *expected)
Compare the digest against a provided hex-encoded digest (32 bytes).
Definition md5.cpp:60
void add(const uint8_t *data, size_t len)
Add bytes of data for the digest.
Definition md5.cpp:16
bool equals_bytes(const uint8_t *expected)
Compare the digest against a provided byte-encoded digest (16 bytes).
Definition md5.cpp:51
uint8_t digest_[16]
Definition md5.h:60
void get_hex(char *output)
Retrieve the MD5 digest as hex characters.
Definition md5.cpp:45
MD5_CTX_TYPE ctx_
Definition md5.h:59
void add(const char *data, size_t len)
Definition md5.h:39
void init()
Initialize a new MD5 digest computation.
Definition md5.cpp:11
void get_bytes(uint8_t *output)
Retrieve the MD5 digest as bytes.
Definition md5.cpp:43
void calculate()
Compute the digest, based on the provided data.
Definition md5.cpp:18
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:279