mirror of
https://github.com/esphome/esphome.git
synced 2025-09-17 18:52:19 +01:00
[md5] Optimize MD5::get_hex() to eliminate sprintf dependency
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include "md5.h"
|
||||
#ifdef USE_MD5
|
||||
@@ -44,7 +43,11 @@ 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++) {
|
||||
sprintf(output + i * 2, "%02x", this->digest_[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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user