DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
hex.h File Reference

Tiny no-stdlib hex encode / decode / nibble helpers (one shared copy). More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Functions

char det_hex_digit (int nibble, bool upper=false)
 Nibble 0..15 -> hex char (lowercase, or uppercase when upper).
 
int det_hex_val (char c)
 Hex digit -> 0..15, or -1 if c is not a hex digit (either case).
 
void det_hex_encode (const uint8_t *in, size_t n, char *out, bool upper=false)
 Encode n bytes as 2*n hex chars + NUL into out (needs cap >= 2*n+1).
 
int det_hex_decode (const char *in, size_t hexlen, uint8_t *out, size_t out_cap)
 Decode exactly hexlen hex chars into out (hexlen/2 bytes).
 

Detailed Description

Tiny no-stdlib hex encode / decode / nibble helpers (one shared copy).

Hex was open-coded in ~10 places (CSRF token, WebDAV XX, provisioning, audit-log hash, device-id, HTTP auth, OAuth2 percent-encode). These header-only inline helpers are the single home for it, mirroring numparse.h - no <stdlib.h>, no heap, and zero link cost when unused.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file hex.h.

Function Documentation

◆ det_hex_digit()

char det_hex_digit ( int  nibble,
bool  upper = false 
)
inline

Nibble 0..15 -> hex char (lowercase, or uppercase when upper).

Definition at line 24 of file hex.h.

◆ det_hex_val()

int det_hex_val ( char  c)
inline

Hex digit -> 0..15, or -1 if c is not a hex digit (either case).

Definition at line 31 of file hex.h.

Referenced by det_hex_decode(), and detws_prov_form_field().

◆ det_hex_encode()

void det_hex_encode ( const uint8_t *  in,
size_t  n,
char *  out,
bool  upper = false 
)
inline

Encode n bytes as 2*n hex chars + NUL into out (needs cap >= 2*n+1).

Parameters
upperuppercase A-F when true, else lowercase a-f.

Definition at line 46 of file hex.h.

◆ det_hex_decode()

int det_hex_decode ( const char *  in,
size_t  hexlen,
uint8_t *  out,
size_t  out_cap 
)
inline

Decode exactly hexlen hex chars into out (hexlen/2 bytes).

Returns
byte count, or -1 on odd length / overflow (> out_cap) / non-hex input.

Definition at line 61 of file hex.h.

References det_hex_val().