libsoup r1038 - in branches/libsoup-2.4: . libsoup tests



Author: danw
Date: Tue Jan 15 14:44:18 2008
New Revision: 1038
URL: http://svn.gnome.org/viewvc/libsoup?rev=1038&view=rev

Log:
	* libsoup/soup-auth-digest.c: Use GChecksum for MD5

	* libsoup/soup-md5-utils.[ch]: gone


Removed:
   branches/libsoup-2.4/libsoup/soup-md5-utils.c
   branches/libsoup-2.4/libsoup/soup-md5-utils.h
Modified:
   branches/libsoup-2.4/ChangeLog
   branches/libsoup-2.4/libsoup/Makefile.am
   branches/libsoup-2.4/libsoup/soup-auth-digest.c
   branches/libsoup-2.4/tests/xmlrpc-test.c

Modified: branches/libsoup-2.4/libsoup/Makefile.am
==============================================================================
--- branches/libsoup-2.4/libsoup/Makefile.am	(original)
+++ branches/libsoup-2.4/libsoup/Makefile.am	Tue Jan 15 14:44:18 2008
@@ -117,8 +117,6 @@
 	soup-gnutls.c			\
 	soup-headers.c			\
 	soup-logger.c			\
-	soup-md5-utils.h		\
-	soup-md5-utils.c		\
 	soup-message.c			\
 	soup-message-body.c		\
 	soup-message-client-io.c	\

Modified: branches/libsoup-2.4/libsoup/soup-auth-digest.c
==============================================================================
--- branches/libsoup-2.4/libsoup/soup-auth-digest.c	(original)
+++ branches/libsoup-2.4/libsoup/soup-auth-digest.c	Tue Jan 15 14:44:18 2008
@@ -16,7 +16,6 @@
 
 #include "soup-auth-digest.h"
 #include "soup-headers.h"
-#include "soup-md5-utils.h"
 #include "soup-message.h"
 #include "soup-message-private.h"
 #include "soup-misc.h"
@@ -254,15 +253,16 @@
 				  const char *password,
 				  char        hex_urp[33])
 {
-	SoupMD5Context ctx;
+	GChecksum *checksum;
 
-	soup_md5_init (&ctx);
-	soup_md5_update (&ctx, username, strlen (username));
-	soup_md5_update (&ctx, ":", 1);
-	soup_md5_update (&ctx, realm, strlen (realm));
-	soup_md5_update (&ctx, ":", 1);
-	soup_md5_update (&ctx, password, strlen (password));
-	soup_md5_final_hex (&ctx, hex_urp);
+	checksum = g_checksum_new (G_CHECKSUM_MD5);
+	g_checksum_update (checksum, username, strlen (username));
+	g_checksum_update (checksum, ":", 1);
+	g_checksum_update (checksum, realm, strlen (realm));
+	g_checksum_update (checksum, ":", 1);
+	g_checksum_update (checksum, password, strlen (password));
+	strncpy (hex_urp, g_checksum_get_string (checksum), 33);
+	g_checksum_free (checksum);
 }
 
 void
@@ -281,18 +281,18 @@
 		 */
 		memcpy (hex_a1, hex_urp, 33);
 	} else {
-		SoupMD5Context ctx;
+		GChecksum *checksum;
 
 		/* In MD5-sess, A1 is hex_urp:nonce:cnonce */
 
-		soup_md5_init (&ctx);
-		soup_md5_update (&ctx, hex_urp, strlen (hex_urp));
-		soup_md5_update (&ctx, ":", 1);
-		soup_md5_update (&ctx, nonce, strlen (nonce));
-		soup_md5_update (&ctx, ":", 1);
-		soup_md5_update (&ctx, cnonce, strlen (cnonce));
-
-		soup_md5_final_hex (&ctx, hex_a1);
+		checksum = g_checksum_new (G_CHECKSUM_MD5);
+		g_checksum_update (checksum, hex_urp, strlen (hex_urp));
+		g_checksum_update (checksum, ":", 1);
+		g_checksum_update (checksum, nonce, strlen (nonce));
+		g_checksum_update (checksum, ":", 1);
+		g_checksum_update (checksum, cnonce, strlen (cnonce));
+		strncpy (hex_a1, g_checksum_get_string (checksum), 33);
+		g_checksum_free (checksum);
 	}
 }
 
@@ -348,39 +348,41 @@
 				   char               response[33])
 {
 	char hex_a2[33];
-	SoupMD5Context md5;
+	GChecksum *checksum;
 
 	/* compute A2 */
-	soup_md5_init (&md5);
-	soup_md5_update (&md5, method, strlen (method));
-	soup_md5_update (&md5, ":", 1);
-	soup_md5_update (&md5, uri, strlen (uri));
-	soup_md5_final_hex (&md5, hex_a2);
+	checksum = g_checksum_new (G_CHECKSUM_MD5);
+	g_checksum_update (checksum, method, strlen (method));
+	g_checksum_update (checksum, ":", 1);
+	g_checksum_update (checksum, uri, strlen (uri));
+	strncpy (hex_a2, g_checksum_get_string (checksum), 33);
+	g_checksum_free (checksum);
 
 	/* compute KD */
-	soup_md5_init (&md5);
-	soup_md5_update (&md5, hex_a1, strlen (hex_a1));
-	soup_md5_update (&md5, ":", 1);
-	soup_md5_update (&md5, nonce, strlen (nonce));
-	soup_md5_update (&md5, ":", 1);
+	checksum = g_checksum_new (G_CHECKSUM_MD5);
+	g_checksum_update (checksum, hex_a1, strlen (hex_a1));
+	g_checksum_update (checksum, ":", 1);
+	g_checksum_update (checksum, nonce, strlen (nonce));
+	g_checksum_update (checksum, ":", 1);
 
 	if (qop) {
 		char tmp[9];
 
 		snprintf (tmp, 9, "%.8x", nc);
-		soup_md5_update (&md5, tmp, strlen (tmp));
-		soup_md5_update (&md5, ":", 1);
-		soup_md5_update (&md5, cnonce, strlen (cnonce));
-		soup_md5_update (&md5, ":", 1);
+		g_checksum_update (checksum, tmp, strlen (tmp));
+		g_checksum_update (checksum, ":", 1);
+		g_checksum_update (checksum, cnonce, strlen (cnonce));
+		g_checksum_update (checksum, ":", 1);
 
 		if (qop != SOUP_AUTH_DIGEST_QOP_AUTH)
 			g_assert_not_reached ();
-		soup_md5_update (&md5, "auth", strlen ("auth"));
-		soup_md5_update (&md5, ":", 1);
+		g_checksum_update (checksum, "auth", strlen ("auth"));
+		g_checksum_update (checksum, ":", 1);
 	}
 
-	soup_md5_update (&md5, hex_a2, 32);
-	soup_md5_final_hex (&md5, response);
+	g_checksum_update (checksum, hex_a2, 32);
+	strncpy (response, g_checksum_get_string (checksum), 33);
+	g_checksum_free (checksum);
 }
 
 static void

Modified: branches/libsoup-2.4/tests/xmlrpc-test.c
==============================================================================
--- branches/libsoup-2.4/tests/xmlrpc-test.c	(original)
+++ branches/libsoup-2.4/tests/xmlrpc-test.c	Tue Jan 15 14:44:18 2008
@@ -9,7 +9,6 @@
 #include <unistd.h>
 
 #include <libsoup/soup.h>
-#include <libsoup/soup-md5-utils.h>
 
 #include "test-utils.h"
 
@@ -185,8 +184,9 @@
 {
 	GByteArray *data, *result;
 	int i;
-	SoupMD5Context md5;
+	GChecksum *checksum;
 	guchar digest[16];
+	gsize digest_len = sizeof (digest);
 	GValue retval;
 	gboolean ok;
 
@@ -197,9 +197,10 @@
 	for (i = 0; i < data->len; i++)
 		data->data[i] = (char)(rand ());
 
-	soup_md5_init (&md5);
-	soup_md5_update (&md5, data->data, data->len);
-	soup_md5_final (&md5, digest);
+	checksum = g_checksum_new (G_CHECKSUM_MD5);
+	g_checksum_update (checksum, data->data, data->len);
+	g_checksum_get_digest (checksum, digest, &digest_len);
+	g_checksum_free (checksum);
 
 	ok = (do_xmlrpc ("md5sum", &retval,
 			 SOUP_TYPE_BYTE_ARRAY, data,
@@ -209,13 +210,13 @@
 	if (!ok)
 		return FALSE;
 
-	if (result->len != 16) {
+	if (result->len != digest_len) {
 		debug_printf (1, "result has WRONG length (%d)\n", result->len);
 		g_byte_array_free (result, TRUE);
 		return FALSE;
 	}
 
-	ok = (memcmp (digest, result->data, 16) == 0);
+	ok = (memcmp (digest, result->data, digest_len) == 0);
 	debug_printf (1, "%s\n", ok ? "OK!" : "WRONG!");
 	g_byte_array_free (result, TRUE);
 	return ok;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]