gnome-keyring r1568 - in trunk: . egg egg/tests gcr



Author: nnielsen
Date: Fri Feb 13 21:30:57 2009
New Revision: 1568
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1568&view=rev

Log:
Allow specifying the delemiter and case of hex encodings.

Modified:
   trunk/ChangeLog
   trunk/egg/egg-hex.c
   trunk/egg/egg-hex.h
   trunk/egg/tests/unit-test-hex.c
   trunk/gcr/gcr-certificate-details-widget.c

Modified: trunk/egg/egg-hex.c
==============================================================================
--- trunk/egg/egg-hex.c	(original)
+++ trunk/egg/egg-hex.c	Fri Feb 13 21:30:57 2009
@@ -25,7 +25,8 @@
 
 #include <string.h>
 
-static const char HEXC[] = "0123456789ABCDEF";
+static const char HEXC_UPPER[] = "0123456789ABCDEF";
+static const char HEXC_LOWER[] = "0123456789abcdef";
 
 guchar*
 egg_hex_decode (const gchar *data, gssize n_data, gsize *n_decoded)
@@ -49,11 +50,11 @@
     		if (!g_ascii_isspace (*data)) {
     			
 	        	/* Find the position */
-			pos = strchr (HEXC, g_ascii_toupper (*data));
+			pos = strchr (HEXC_UPPER, g_ascii_toupper (*data));
 			if (pos == 0)
 				break;
 
-			j = pos - HEXC;
+			j = pos - HEXC_UPPER;
 			if(!state) {
 				*decoded = (j & 0xf) << 4;
 				state = 1;
@@ -81,17 +82,21 @@
 gchar* 
 egg_hex_encode (const guchar *data, gsize n_data)
 {
-	return egg_hex_encode_full (data, n_data, 0);
+	return egg_hex_encode_full (data, n_data, TRUE, '\0', 0);
 }
 
 gchar*
-egg_hex_encode_full (const guchar *data, gsize n_data, guint group)
+egg_hex_encode_full (const guchar *data, gsize n_data,
+                     gboolean upper_case, gchar delim, guint group)
 {
 	GString *result;
+	const char *hexc;
 	gsize bytes;
 	guchar j;
 	
 	g_return_val_if_fail (data || !n_data, NULL);
+	
+	hexc = upper_case ? HEXC_UPPER : HEXC_LOWER;
 
 	result = g_string_sized_new (n_data * 2 + 1);
 	bytes = 0;
@@ -99,13 +104,13 @@
 	while (n_data > 0) {
 		
 		if (group && bytes && (bytes % group) == 0)
-			g_string_append_c (result, ' ');
+			g_string_append_c (result, delim);
 
 		j = *(data) >> 4 & 0xf;
-		g_string_append_c (result, HEXC[j]);
+		g_string_append_c (result, hexc[j]);
 		
 		j = *(data++) & 0xf;
-		g_string_append_c (result, HEXC[j]);
+		g_string_append_c (result, hexc[j]);
     
 		++bytes;
 		--n_data;

Modified: trunk/egg/egg-hex.h
==============================================================================
--- trunk/egg/egg-hex.h	(original)
+++ trunk/egg/egg-hex.h	Fri Feb 13 21:30:57 2009
@@ -33,6 +33,8 @@
 
 gchar*                egg_hex_encode_full                    (const guchar *data, 
                                                               gsize n_data,
+                                                              gboolean upper_case,
+                                                              gchar delim,
                                                               guint group);
 
 #endif /* EGG_HEX_H_ */

Modified: trunk/egg/tests/unit-test-hex.c
==============================================================================
--- trunk/egg/tests/unit-test-hex.c	(original)
+++ trunk/egg/tests/unit-test-hex.c	Fri Feb 13 21:30:57 2009
@@ -48,12 +48,12 @@
 	gchar *hex;
 	
 	/* Encode without spaces */
-	hex = egg_hex_encode_full (TEST_DATA, sizeof (TEST_DATA), 0);
+	hex = egg_hex_encode_full (TEST_DATA, sizeof (TEST_DATA), TRUE, 0, 0);
 	g_assert (hex);
 	g_assert_cmpstr (hex, ==, TEST_HEX);
 	
-	/* Encode without spaces */
-	hex = egg_hex_encode_full (TEST_DATA, sizeof (TEST_DATA), 1);
+	/* Encode with spaces */
+	hex = egg_hex_encode_full (TEST_DATA, sizeof (TEST_DATA), TRUE, ' ', 1);
 	g_assert (hex);
 	g_assert_cmpstr (hex, ==, TEST_HEX_DELIM);
 }

Modified: trunk/gcr/gcr-certificate-details-widget.c
==============================================================================
--- trunk/gcr/gcr-certificate-details-widget.c	(original)
+++ trunk/gcr/gcr-certificate-details-widget.c	Fri Feb 13 21:30:57 2009
@@ -165,7 +165,7 @@
 	g_checksum_get_digest (checksum, buffer, &n_buffer);
 	g_checksum_free (checksum);
 	
-	display = egg_hex_encode_full (buffer, n_buffer, 1);
+	display = egg_hex_encode_full (buffer, n_buffer, TRUE, ' ', 1);
 	append_field_and_value (self, name, display, TRUE);
 	g_free (display);
 	
@@ -255,7 +255,7 @@
 	
 	value = egg_asn1_read_content (asn, data, n_data, "tbsCertificate.serialNumber", &n_value);
 	g_return_if_fail (value);
-	display = egg_hex_encode_full (value, n_value, 1);
+	display = egg_hex_encode_full (value, n_value, TRUE, ' ', 1);
 	append_field_and_value (self, _("Serial Number"), display, TRUE);
 	g_free (display);
 	
@@ -280,7 +280,7 @@
 	
 	value = egg_asn1_read_content (asn, data, n_data, "signature", &n_value);
 	g_return_if_fail (value);
-	display = egg_hex_encode_full (value, n_value, 1);
+	display = egg_hex_encode_full (value, n_value, TRUE, ' ', 1);
 	append_field_and_value (self, _("Signature"), display, TRUE);
 	g_free (display);
 
@@ -293,7 +293,7 @@
 	
 	value = egg_asn1_read_content (asn, data, n_data, "tbsCertificate.subjectPublicKeyInfo.subjectPublicKey", &n_value);
 	g_return_if_fail (value);
-	display = egg_hex_encode_full (value, n_value, 1);
+	display = egg_hex_encode_full (value, n_value, TRUE, ' ', 1);
 	append_field_and_value (self, _("Public Key"), display, TRUE);
 	g_free (display);
 	



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