![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Functions | |
| 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. | |
| 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). | |
| 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. | |
| 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. | |
| 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.
Definition at line 71 of file n_hex.c.
References __n_assert, LOG_ERR, Malloc, n_hex_value(), and n_log.
Referenced by test_decode_errors(), and test_decode_roundtrip().
| 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.
Definition at line 141 of file n_hex.c.
References __n_assert, LOG_ERR, n_hex_value(), and n_log.
Referenced by test_bounded().
| 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.
Definition at line 48 of file n_hex.c.
References __n_assert, N_STR::data, LOG_ERR, n_hex_digits, n_log, new_nstr(), and N_STR::written.
Referenced by expect_encode(), expect_hex(), n_digest_sha256_hex(), n_random_hex_token(), and test_decode_roundtrip().
| 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).
Definition at line 117 of file n_hex.c.
References __n_assert, LOG_ERR, n_hex_digits, and n_log.
Referenced by test_bounded().