Browse Source

Expose hex_decode_digit from util.c

svn:r17706
Nick Mathewson 15 years ago
parent
commit
efb863189c
2 changed files with 11 additions and 3 deletions
  1. 10 3
      src/common/util.c
  2. 1 0
      src/common/util.h

+ 10 - 3
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;

+ 1 - 0
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);