mirror of
https://github.com/esphome/esphome.git
synced 2025-10-18 09:43:47 +01:00
Merge branch 'integration' into memory_api
This commit is contained in:
@@ -39,13 +39,6 @@ void MD5Digest::add(const uint8_t *data, size_t len) { br_md5_update(&this->ctx_
|
|||||||
void MD5Digest::calculate() { br_md5_out(&this->ctx_, this->digest_); }
|
void MD5Digest::calculate() { br_md5_out(&this->ctx_, this->digest_); }
|
||||||
#endif // USE_RP2040
|
#endif // USE_RP2040
|
||||||
|
|
||||||
bool MD5Digest::equals_hex(const char *expected) {
|
|
||||||
uint8_t parsed[16];
|
|
||||||
if (!parse_hex(expected, parsed, 16))
|
|
||||||
return false;
|
|
||||||
return equals_bytes(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace md5
|
} // namespace md5
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
#endif
|
#endif
|
||||||
|
@@ -45,9 +45,6 @@ class MD5Digest : public HashBase {
|
|||||||
/// Get the size of the hex output (32 for MD5)
|
/// Get the size of the hex output (32 for MD5)
|
||||||
size_t get_hex_size() const override { return 32; }
|
size_t get_hex_size() const override { return 32; }
|
||||||
|
|
||||||
/// Compare the digest against a provided hex-encoded digest (32 bytes).
|
|
||||||
bool equals_hex(const char *expected);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MD5_CTX_TYPE ctx_{};
|
MD5_CTX_TYPE ctx_{};
|
||||||
};
|
};
|
||||||
|
@@ -84,14 +84,6 @@ std::string SHA256::get_hex_string() {
|
|||||||
return std::string(buf);
|
return std::string(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHA256::equals_hex(const char *expected) {
|
|
||||||
uint8_t parsed[32];
|
|
||||||
if (!parse_hex(expected, parsed, 32)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return this->equals_bytes(parsed);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace esphome::sha256
|
} // namespace esphome::sha256
|
||||||
|
|
||||||
#endif // Platform check
|
#endif // Platform check
|
||||||
|
@@ -38,8 +38,6 @@ class SHA256 : public esphome::HashBase {
|
|||||||
/// Get the size of the hex output (64 for SHA256)
|
/// Get the size of the hex output (64 for SHA256)
|
||||||
size_t get_hex_size() const override { return 64; }
|
size_t get_hex_size() const override { return 64; }
|
||||||
|
|
||||||
bool equals_hex(const char *expected);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||||
mbedtls_sha256_context ctx_{};
|
mbedtls_sha256_context ctx_{};
|
||||||
|
@@ -22,8 +22,18 @@ class HashBase {
|
|||||||
/// Compute the hash based on provided data
|
/// Compute the hash based on provided data
|
||||||
virtual void calculate() = 0;
|
virtual void calculate() = 0;
|
||||||
|
|
||||||
|
/// Retrieve the hash as bytes
|
||||||
|
void get_bytes(uint8_t *output) {
|
||||||
|
const size_t hash_bytes = this->get_hex_size() / 2;
|
||||||
|
memcpy(output, this->digest_, hash_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
/// Retrieve the hash as hex characters
|
/// Retrieve the hash as hex characters
|
||||||
|
<<<<<<< HEAD
|
||||||
virtual void get_hex(char *output) {
|
virtual void get_hex(char *output) {
|
||||||
|
=======
|
||||||
|
void get_hex(char *output) {
|
||||||
|
>>>>>>> integration
|
||||||
const size_t hash_bytes = this->get_hex_size() / 2;
|
const size_t hash_bytes = this->get_hex_size() / 2;
|
||||||
for (size_t i = 0; i < hash_bytes; i++) {
|
for (size_t i = 0; i < hash_bytes; i++) {
|
||||||
uint8_t byte = this->digest_[i];
|
uint8_t byte = this->digest_[i];
|
||||||
@@ -32,23 +42,43 @@ class HashBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
/// Retrieve the hash as bytes
|
/// Retrieve the hash as bytes
|
||||||
void get_bytes(uint8_t *output) {
|
void get_bytes(uint8_t *output) {
|
||||||
const size_t hash_bytes = this->get_hex_size() / 2;
|
const size_t hash_bytes = this->get_hex_size() / 2;
|
||||||
memcpy(output, this->digest_, hash_bytes);
|
memcpy(output, this->digest_, hash_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> integration
|
||||||
/// Compare the hash against a provided byte-encoded hash
|
/// Compare the hash against a provided byte-encoded hash
|
||||||
bool equals_bytes(const uint8_t *expected) {
|
bool equals_bytes(const uint8_t *expected) {
|
||||||
const size_t hash_bytes = this->get_hex_size() / 2;
|
const size_t hash_bytes = this->get_hex_size() / 2;
|
||||||
return memcmp(this->digest_, expected, hash_bytes) == 0;
|
return memcmp(this->digest_, expected, hash_bytes) == 0;
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
|
||||||
|
/// Compare the hash against a provided hex-encoded hash
|
||||||
|
bool equals_hex(const char *expected) {
|
||||||
|
const size_t hash_bytes = this->get_hex_size() / 2;
|
||||||
|
uint8_t parsed[32]; // Max size for SHA256
|
||||||
|
if (!parse_hex(expected, parsed, hash_bytes)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this->equals_bytes(parsed);
|
||||||
|
}
|
||||||
|
>>>>>>> integration
|
||||||
|
|
||||||
/// Get the size of the hex output (32 for MD5, 64 for SHA256)
|
/// Get the size of the hex output (32 for MD5, 64 for SHA256)
|
||||||
virtual size_t get_hex_size() const = 0;
|
virtual size_t get_hex_size() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
<<<<<<< HEAD
|
||||||
uint8_t digest_[32]; // Common digest storage (MD5 uses 16 bytes, SHA256 uses 32)
|
uint8_t digest_[32]; // Common digest storage (MD5 uses 16 bytes, SHA256 uses 32)
|
||||||
|
=======
|
||||||
|
uint8_t digest_[32]; // Common digest storage, sized for largest hash (SHA256)
|
||||||
|
>>>>>>> integration
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
Reference in New Issue
Block a user