mirror of
https://github.com/esphome/esphome.git
synced 2025-09-22 13:12:22 +01:00
move context to .h
This commit is contained in:
@@ -2,19 +2,9 @@
|
|||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#ifdef USE_ESP32
|
|
||||||
#include "mbedtls/sha256.h"
|
|
||||||
#elif defined(USE_ARDUINO)
|
|
||||||
#include <SHA256.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace esphome::sha256 {
|
namespace esphome::sha256 {
|
||||||
|
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
struct SHA256::SHA256Context {
|
|
||||||
mbedtls_sha256_context ctx;
|
|
||||||
uint8_t hash[32];
|
|
||||||
};
|
|
||||||
|
|
||||||
SHA256::~SHA256() {
|
SHA256::~SHA256() {
|
||||||
if (this->ctx_) {
|
if (this->ctx_) {
|
||||||
@@ -46,12 +36,6 @@ void SHA256::calculate() {
|
|||||||
|
|
||||||
#elif defined(USE_ARDUINO)
|
#elif defined(USE_ARDUINO)
|
||||||
|
|
||||||
struct SHA256::SHA256Context {
|
|
||||||
::SHA256 sha;
|
|
||||||
uint8_t hash[32];
|
|
||||||
bool calculated{false};
|
|
||||||
};
|
|
||||||
|
|
||||||
SHA256::~SHA256() = default;
|
SHA256::~SHA256() = default;
|
||||||
|
|
||||||
void SHA256::init() {
|
void SHA256::init() {
|
||||||
|
@@ -5,6 +5,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#ifdef USE_ESP32
|
||||||
|
#include "mbedtls/sha256.h"
|
||||||
|
#elif defined(USE_ARDUINO)
|
||||||
|
#include <SHA256.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace esphome::sha256 {
|
namespace esphome::sha256 {
|
||||||
|
|
||||||
class SHA256 {
|
class SHA256 {
|
||||||
@@ -27,7 +33,20 @@ class SHA256 {
|
|||||||
bool equals_hex(const char *expected);
|
bool equals_hex(const char *expected);
|
||||||
|
|
||||||
protected:
|
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<SHA256Context> ctx_;
|
std::unique_ptr<SHA256Context> ctx_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user