HEX: hexadecimal encode and decode
Functions
| Name | |
|---|---|
| size_t | n_hex_encode_to(char * out, size_t out_size, const unsigned char * data, size_t len) encode len bytes of data as lowercase hex into the caller-provided buffer out (needs out_size >= 2*len+1), NUL-terminating on success. |
| N_STR * | n_hex_encode(const unsigned char * data, size_t len) encode len bytes of data as a lowercase hex N_STR (2*len characters); free with free_nstr. |
| int | n_hex_decode_to(unsigned char * out, size_t out_size, const char * hex, size_t nbytes) decode exactly nbytes bytes from the first 2*nbytes hex digits of hex (case-insensitive, no embedded whitespace) into the caller-provided buffer out (needs out_size >= nbytes). |
| unsigned char * | n_hex_decode(const char * hex, size_t * out_len) decode a hex string (ASCII whitespace between digits is ignored) into a freshly allocated, NUL-terminated byte buffer; *out_len receives the decoded byte count. |
Functions Documentation
function n_hex_encode_to
size_t n_hex_encode_to(
char * out,
size_t out_size,
const unsigned char * data,
size_t len
)
encode len bytes of data as lowercase hex into the caller-provided buffer out (needs out_size >= 2*len+1), NUL-terminating on success.
Zero-allocation variant of n_hex_encode. Returns the number of hex characters written (2*len), or 0 on a NULL out, NULL/oversized data, or a too-small buffer (out left untouched).
function n_hex_encode
N_STR * n_hex_encode(
const unsigned char * data,
size_t len
)
encode len bytes of data as a lowercase hex N_STR (2*len characters); free with free_nstr.
Returns NULL on a NULL/oversized input or on allocation failure.
function n_hex_decode_to
int n_hex_decode_to(
unsigned char * out,
size_t out_size,
const char * hex,
size_t nbytes
)
decode exactly nbytes bytes from the first 2*nbytes hex digits of hex (case-insensitive, no embedded whitespace) into the caller-provided buffer out (needs out_size >= nbytes).
Zero-allocation, fixed-length counterpart to n_hex_decode. Returns TRUE on success, FALSE on a too-small buffer, a hex string shorter than 2*nbytes, or an invalid hex digit.
function n_hex_decode
unsigned char * n_hex_decode(
const char * hex,
size_t * out_len
)
decode a hex string (ASCII whitespace between digits is ignored) into a freshly allocated, NUL-terminated byte buffer; *out_len receives the decoded byte count.
Free the buffer with Free()/free(). Returns NULL on an odd number of hex digits or an invalid character.
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB