diff --git a/esphome/components/sha256/sha256.cpp b/esphome/components/sha256/sha256.cpp index 94f623f2fa..a3e06cae2f 100644 --- a/esphome/components/sha256/sha256.cpp +++ b/esphome/components/sha256/sha256.cpp @@ -2,19 +2,9 @@ #include "esphome/core/helpers.h" #include -#ifdef USE_ESP32 -#include "mbedtls/sha256.h" -#elif defined(USE_ARDUINO) -#include -#endif - namespace esphome::sha256 { #ifdef USE_ESP32 -struct SHA256::SHA256Context { - mbedtls_sha256_context ctx; - uint8_t hash[32]; -}; SHA256::~SHA256() { if (this->ctx_) { @@ -46,12 +36,6 @@ void SHA256::calculate() { #elif defined(USE_ARDUINO) -struct SHA256::SHA256Context { - ::SHA256 sha; - uint8_t hash[32]; - bool calculated{false}; -}; - SHA256::~SHA256() = default; void SHA256::init() { diff --git a/esphome/components/sha256/sha256.h b/esphome/components/sha256/sha256.h index dd1742ea0d..5917f68572 100644 --- a/esphome/components/sha256/sha256.h +++ b/esphome/components/sha256/sha256.h @@ -5,6 +5,12 @@ #include #include +#ifdef USE_ESP32 +#include "mbedtls/sha256.h" +#elif defined(USE_ARDUINO) +#include +#endif + namespace esphome::sha256 { class SHA256 { @@ -27,7 +33,20 @@ class SHA256 { bool equals_hex(const char *expected); protected: - struct SHA256Context; +#ifdef USE_ESP32 + struct SHA256Context { + mbedtls_sha256_context ctx; + uint8_t hash[32]; + }; +#elif defined(USE_ARDUINO) + struct SHA256Context { + ::SHA256 sha; + uint8_t hash[32]; + bool calculated{false}; + }; +#else +#error "SHA256 not supported on this platform" +#endif std::unique_ptr ctx_; };