1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-07 20:33:47 +01:00
This commit is contained in:
J. Nick Koston
2025-09-14 13:51:10 -05:00
parent b03a651499
commit 22c91dfadc
3 changed files with 5 additions and 5 deletions

View File

@@ -44,10 +44,8 @@ void MD5Digest::get_bytes(uint8_t *output) { memcpy(output, this->digest_, 16);
void MD5Digest::get_hex(char *output) {
for (size_t i = 0; i < 16; i++) {
uint8_t byte = this->digest_[i];
uint8_t high = byte >> 4;
uint8_t low = byte & 0x0F;
output[i * 2] = high < 10 ? '0' + high : 'a' + (high - 10);
output[i * 2 + 1] = low < 10 ? '0' + low : 'a' + (low - 10);
output[i * 2] = format_hex_char(byte >> 4);
output[i * 2 + 1] = format_hex_char(byte & 0x0F);
}
}

View File

@@ -258,7 +258,6 @@ std::string format_mac_address_pretty(const uint8_t *mac) {
return str_snprintf("%02X:%02X:%02X:%02X:%02X:%02X", 17, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
static char format_hex_char(uint8_t v) { return v >= 10 ? 'a' + (v - 10) : '0' + v; }
std::string format_hex(const uint8_t *data, size_t length) {
std::string ret;
ret.resize(length * 2);

View File

@@ -380,6 +380,9 @@ template<typename T, enable_if_t<std::is_unsigned<T>::value, int> = 0> optional<
return parse_hex<T>(str.c_str(), str.length());
}
/// Convert a nibble (0-15) to lowercase hex char
inline char format_hex_char(uint8_t v) { return v >= 10 ? 'a' + (v - 10) : '0' + v; }
/// Format the six-byte array \p mac into a MAC address.
std::string format_mac_address_pretty(const uint8_t mac[6]);
/// Format the byte array \p data of length \p len in lowercased hex.