mirror of
https://github.com/esphome/esphome.git
synced 2026-10-06 02:51:29 +00:00
Introduce hex parsing & formatting helper functions (#2882)
This commit is contained in:
@@ -23,7 +23,7 @@ void MD5Digest::get_hex(char *output) {
|
||||
}
|
||||
}
|
||||
|
||||
bool MD5Digest::equals_bytes(const char *expected) {
|
||||
bool MD5Digest::equals_bytes(const uint8_t *expected) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
if (expected[i] != this->digest_[i]) {
|
||||
return false;
|
||||
@@ -33,18 +33,10 @@ bool MD5Digest::equals_bytes(const char *expected) {
|
||||
}
|
||||
|
||||
bool MD5Digest::equals_hex(const char *expected) {
|
||||
for (size_t i = 0; i < 16; i++) {
|
||||
auto high = parse_hex(expected[i * 2]);
|
||||
auto low = parse_hex(expected[i * 2 + 1]);
|
||||
if (!high.has_value() || !low.has_value()) {
|
||||
return false;
|
||||
}
|
||||
auto value = (*high << 4) | *low;
|
||||
if (value != this->digest_[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
uint8_t parsed[16];
|
||||
if (!parse_hex(expected, parsed, 16))
|
||||
return false;
|
||||
return equals_bytes(parsed);
|
||||
}
|
||||
|
||||
} // namespace md5
|
||||
|
||||
Reference in New Issue
Block a user