src/string.cpp
changeset 11178 aa617a8b4f34
parent 10429 1b99254f9607
--- a/src/string.cpp	Fri Jul 18 22:41:08 2008 +0300
+++ b/src/string.cpp	Sat Jul 19 01:38:52 2008 +0300
@@ -203,6 +203,28 @@
 	return p;
 }
 
+/** Convert the hexadecimal string representation to a binary md5sum
+ * @param md5sum where to put the md5sum into
+ * @param buf buffer containing a string of 32 hex chars
+ * @return 0 on success, -1 on failure */
+int StringToMd5sum(uint8 md5sum[16], const char *buf)
+{
+    char hex[3] = { 0, 0, 0};
+    char *invalid;
+
+	for (uint i = 0; i < 16; i++) {
+        hex[0] = buf[i * 2 + 0];
+        hex[1] = buf[i * 2 + 1];
+
+        md5sum[i] = strtol(hex, &invalid, 16);
+
+        if (*invalid)
+            return -1;
+	}
+
+	return 0;
+}
+
 
 /* UTF-8 handling routines */