Merge branch 'ms/core-icase-doc'
[gitweb.git] / hex.c
diff --git a/hex.c b/hex.c
index 28b44118cbf2c75b26d017a34ecfdf65dbf4c7eb..8df2d63728f0405a9b1dc70aa404954dd921b6bc 100644 (file)
--- a/hex.c
+++ b/hex.c
@@ -35,6 +35,18 @@ const signed char hexval_table[256] = {
         -1, -1, -1, -1, -1, -1, -1, -1,                /* f8-ff */
 };
 
+int hex_to_bytes(unsigned char *binary, const char *hex, size_t len)
+{
+       for (; len; len--, hex += 2) {
+               unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]);
+
+               if (val & ~0xff)
+                       return -1;
+               *binary++ = val;
+       }
+       return 0;
+}
+
 int get_sha1_hex(const char *hex, unsigned char *sha1)
 {
        int i;