From c22fa15f5c44a43e291c15f737515e35fb9dc6ba Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 24 Oct 2026 02:00:42 +0200 Subject: Move all code converting between binary and hex representation to its own unit --- ot_hex.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ot_hex.h (limited to 'ot_hex.h') diff --git a/ot_hex.h b/ot_hex.h new file mode 100644 index 0000000..cb2e86f --- /dev/null +++ b/ot_hex.h @@ -0,0 +1,25 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. + + $id$ */ + +#ifndef OT_HEX_H__ +#define OT_HEX_H__ + +#include + +#include "trackerlogic.h" + +/* Write hash as forty upper case hex digits followed by a terminating zero. + dest must have room for forty one bytes. Returns dest. */ +char *hex_fromhash(char *dest, const uint8_t *hash); + +/* Read forty hex digits from src into hash. Returns non-zero on success. + On failure hash is left untouched and no byte of src beyond the offending + character is read, so src need not be forty characters long. */ +int hex_tohash(ot_hash hash, const char *src); + +/* Non-zero if c is a hexadecimal digit, in either case. */ +int hex_isdigit(int c); + +#endif -- cgit v1.3