diff libpurple/protocols/jabber/jutil.c @ 24693:61e0924de04a

Fix up the XMPP User Avatar SHA1 hashing so that we don't mess up the checksum when bytes in the checksum start with 0 (for example, 430902... would become 4392...). Refs #7734, which has a second patch needing more detailed review. committer: John Bailey <rekkanoryo@rekkanoryo.org>
author Paul Aurich <paul@darkrain42.org>
date Thu, 11 Dec 2008 08:08:02 +0000
parents 44b4e8bd759b
children 34e4e2ca7db9
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jutil.c	Thu Dec 11 07:38:20 2008 +0000
+++ b/libpurple/protocols/jabber/jutil.c	Thu Dec 11 08:08:02 2008 +0000
@@ -20,7 +20,9 @@
  */
 #include "internal.h"
 #include "account.h"
+#include "cipher.h"
 #include "conversation.h"
+#include "debug.h"
 #include "server.h"
 #include "util.h"
 #include "xmlnode.h"
@@ -236,3 +238,29 @@
 	return NULL;
 }
 
+/* The same as purple_util_get_image_checksum, but guaranteed to remain SHA1 */
+char *
+jabber_calculate_data_sha1sum(gconstpointer data, size_t len)
+{
+	PurpleCipherContext *context;
+	static gchar digest[41];
+
+	context = purple_cipher_context_new_by_name("sha1", NULL);
+	if (context == NULL)
+	{
+		purple_debug_error("jabber", "Could not find sha1 cipher\n");
+		g_return_val_if_reached(NULL);
+	}
+
+	/* Hash the data */
+	purple_cipher_context_append(context, data, len);
+	if (!purple_cipher_context_digest_to_str(context, sizeof(digest), digest, NULL))
+	{
+		purple_debug_error("jabber", "Failed to get SHA-1 digest.\n");
+		g_return_val_if_reached(NULL);
+	}
+	purple_cipher_context_destroy(context);
+
+	return g_strdup(digest);
+}
+