diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util.c | 13 | ||||
-rw-r--r-- | src/common/util.h | 1 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/common/util.c b/src/common/util.c index b00d26cba4..ec2b1c9767 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -758,7 +758,7 @@ base16_encode(char *dest, size_t destlen, const char *src, size_t srclen) /** Helper: given a hex digit, return its value, or -1 if it isn't hex. */ static INLINE int -hex_decode_digit(char c) +_hex_decode_digit(char c) { switch (c) { case '0': return 0; @@ -782,6 +782,13 @@ hex_decode_digit(char c) } } +/** Helper: given a hex digit, return its value, or -1 if it isn't hex. */ +int +hex_decode_digit(char c) +{ + return _hex_decode_digit(c); +} + /** Given a hexadecimal string of <b>srclen</b> bytes in <b>src</b>, decode it * and store the result in the <b>destlen</b>-byte buffer at <b>dest</b>. * Return 0 on success, -1 on failure. */ @@ -797,8 +804,8 @@ base16_decode(char *dest, size_t destlen, const char *src, size_t srclen) return -1; end = src+srclen; while (src<end) { - v1 = hex_decode_digit(*src); - v2 = hex_decode_digit(*(src+1)); + v1 = _hex_decode_digit(*src); + v2 = _hex_decode_digit(*(src+1)); if (v1<0||v2<0) return -1; *(uint8_t*)dest = (v1<<4)|v2; diff --git a/src/common/util.h b/src/common/util.h index 029cad9e3f..bcecdae49d 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -198,6 +198,7 @@ struct smartlist_t; void wrap_string(struct smartlist_t *out, const char *string, size_t width, const char *prefix0, const char *prefixRest); +int hex_decode_digit(char c); void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen); int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen); |