e2ee: fix to_hex for proper hexadecimal encoding and adjust type casting

This commit is contained in:
ekoby
2026-05-27 13:23:48 -04:00
parent f9bae4fbc6
commit 01380adee7
2 changed files with 11 additions and 5 deletions
+4
View File
@@ -28,3 +28,7 @@ local.cmake
## CI dirs
.ci.cache/
# AI agent files
/CLAUDE.md
/AGENTS.md
+7 -5
View File
@@ -22,14 +22,16 @@
extern "C" {
#endif
static inline const char* to_hex(const uint8_t *bin, size_t len) {
static inline const char* to_hex(const uint8_t *bin, unsigned len) {
static char buf[1024];
const uint8_t *b = bin;
char *p = buf;
while (b - bin < len && p - buf < sizeof(buf) - 2) {
*p++ = (char)('0' + (*bin >> 4));
*p++ = (char)('0' + (*bin & 0x0F));
bin++;
uint8_t hi = *b >> 4;
uint8_t lo = *b & 0x0F;
*p++ = (char)( hi < 10 ? '0' + hi : 'a' + hi - 10 );
*p++ = (char)( lo < 10 ? '0' + lo : 'a' + lo - 10 );
b++;
}
*p = '\0';
return buf;
@@ -39,7 +41,7 @@ static inline const char* to_hex(const uint8_t *bin, size_t len) {
#if ZITI_E2EE_DEBUG
#define PRINT_BYTES(label, buf, len) do { \
ZITI_LOG(DEBUG, "%s: %s", label, to_hex(buf, len)); \
ZITI_LOG(DEBUG, "%s: %s", label, to_hex(buf, (unsigned)len)); \
} while(0)
#else
#define PRINT_BYTES(label, buf, len) do {} while(0)