loudmouth/lm-sha.c
changeset 497 bb4157a604ec
parent 162 16d29898f97b
child 518 cdd6a0c5b439
--- a/loudmouth/lm-sha.c	Thu Aug 28 14:41:14 2008 +0200
+++ b/loudmouth/lm-sha.c	Thu Aug 28 15:15:28 2008 +0200
@@ -597,29 +597,35 @@
   }
 }
 
-#ifdef G_OS_WIN32
-#define snprintf _snprintf
-#endif
-
-const gchar *
+/**
+ * lm_sha_hash:
+ * @str: the input string
+ *
+ * Computes the SHA1 checksum of @str and prints it in text mode.
+ *
+ * Return value: A newly allocated string.
+ **/
+gchar *
 lm_sha_hash (const gchar *str)
 {
-        static gchar  ret_val[41];
-        SHA1Context   ctx;
-        guint8         hash[SHA1_HASH_SIZE];
-        gchar        *ch;
-        guint          i;
-        
-        SHA1Init (&ctx);
-        SHA1Update (&ctx, str, strlen (str));
-        SHA1Final (&ctx, hash);
+	gchar        *ret_val;
+	SHA1Context   ctx;
+	guint8        hash[SHA1_HASH_SIZE];
+	gchar        *ch;
+	guint         i;
+
+	ret_val = g_malloc (SHA1_HASH_SIZE*2 + 1);
 
-        ch = ret_val;
+	SHA1Init (&ctx);
+	SHA1Update (&ctx, str, strlen (str));
+	SHA1Final (&ctx, hash);
+
+	ch = ret_val;
 
-        for (i = 0; i < SHA1_HASH_SIZE; ++i) {
-                snprintf (ch, 3, "%02x", hash[i]);
-                ch += 2;
-        }
+	for (i = 0; i < SHA1_HASH_SIZE; ++i) {
+		g_snprintf (ch, 3, "%02x", hash[i]);
+		ch += 2;
+	}
 
-        return (const gchar *) ret_val;
+	return ret_val;
 }