Paul Nasrat 266b7c
diff -r 39cb695c7c8b rpmio/base64.c
Paul Nasrat 266b7c
--- a/rpmio/base64.c	Thu Nov 01 10:42:01 2007 +0100
Paul Nasrat 266b7c
+++ b/rpmio/base64.c	Wed Nov 14 18:16:51 2007 +0100
Paul Nasrat 266b7c
@@ -98,21 +98,20 @@ char *b64encode(const void *data, size_t
Paul Nasrat 266b7c
 	return output;
Paul Nasrat 266b7c
 }
Paul Nasrat 266b7c
 
Paul Nasrat 266b7c
-static int base64_decode_value(char value_in)
Paul Nasrat 266b7c
-{
Paul Nasrat 266b7c
-	static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
Paul Nasrat 266b7c
-	static const char decoding_size = sizeof(decoding);
Paul Nasrat 266b7c
+static int base64_decode_value(unsigned char value_in)
Paul Nasrat 266b7c
+{
Paul Nasrat 266b7c
+	static const int decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
Paul Nasrat 266b7c
 	value_in -= 43;
Paul Nasrat 266b7c
-	if (value_in < 0 || value_in > decoding_size)
Paul Nasrat 266b7c
+	if (value_in > sizeof(decoding)/sizeof(int))
Paul Nasrat 266b7c
 		return -1;
Paul Nasrat 266b7c
-	return decoding[(int)value_in];
Paul Nasrat 266b7c
+	return decoding[value_in];
Paul Nasrat 266b7c
 }
Paul Nasrat 266b7c
 
Paul Nasrat 266b7c
 static size_t base64_decode_block(const char *code_in, const size_t length_in, char *plaintext_out)
Paul Nasrat 266b7c
 {
Paul Nasrat 266b7c
 	const char *codechar = code_in;
Paul Nasrat 266b7c
 	char *plainchar = plaintext_out;
Paul Nasrat 266b7c
-	char fragment;
Paul Nasrat 266b7c
+	int fragment;
Paul Nasrat 266b7c
 	
Paul Nasrat 266b7c
 	*plainchar = 0;
Paul Nasrat 266b7c
 	
Paul Nasrat 266b7c
@@ -123,38 +122,38 @@ static size_t base64_decode_block(const 
Paul Nasrat 266b7c
 			{
Paul Nasrat 266b7c
 				return plainchar - plaintext_out;
Paul Nasrat 266b7c
 			}
Paul Nasrat 266b7c
-			fragment = (char)base64_decode_value(*codechar++);
Paul Nasrat 266b7c
-		} while (fragment < 0);
Paul Nasrat 266b7c
-		*plainchar    = (fragment & 0x03f) << 2;
Paul Nasrat 266b7c
-
Paul Nasrat 266b7c
-		do {
Paul Nasrat 266b7c
-			if (codechar == code_in+length_in)
Paul Nasrat 266b7c
-			{
Paul Nasrat 266b7c
-				return plainchar - plaintext_out;
Paul Nasrat 266b7c
-			}
Paul Nasrat 266b7c
-			fragment = (char)base64_decode_value(*codechar++);
Paul Nasrat 266b7c
-		} while (fragment < 0);
Paul Nasrat 266b7c
-		*plainchar++ |= (fragment & 0x030) >> 4;
Paul Nasrat 266b7c
-		*plainchar    = (fragment & 0x00f) << 4;
Paul Nasrat 266b7c
-
Paul Nasrat 266b7c
-		do {
Paul Nasrat 266b7c
-			if (codechar == code_in+length_in)
Paul Nasrat 266b7c
-			{
Paul Nasrat 266b7c
-				return plainchar - plaintext_out;
Paul Nasrat 266b7c
-			}
Paul Nasrat 266b7c
-			fragment = (char)base64_decode_value(*codechar++);
Paul Nasrat 266b7c
-		} while (fragment < 0);
Paul Nasrat 266b7c
-		*plainchar++ |= (fragment & 0x03c) >> 2;
Paul Nasrat 266b7c
-		*plainchar    = (fragment & 0x003) << 6;
Paul Nasrat 266b7c
-
Paul Nasrat 266b7c
-		do {
Paul Nasrat 266b7c
-			if (codechar == code_in+length_in)
Paul Nasrat 266b7c
-			{
Paul Nasrat 266b7c
-				return plainchar - plaintext_out;
Paul Nasrat 266b7c
-			}
Paul Nasrat 266b7c
-			fragment = (char)base64_decode_value(*codechar++);
Paul Nasrat 266b7c
-		} while (fragment < 0);
Paul Nasrat 266b7c
-		*plainchar++   |= (fragment & 0x03f);
Paul Nasrat 266b7c
+			fragment = base64_decode_value(*codechar++);
Paul Nasrat 266b7c
+		} while (fragment < 0);
Paul Nasrat 266b7c
+		*plainchar    = (char)((fragment & 0x03f) << 2);
Paul Nasrat 266b7c
+
Paul Nasrat 266b7c
+		do {
Paul Nasrat 266b7c
+			if (codechar == code_in+length_in)
Paul Nasrat 266b7c
+			{
Paul Nasrat 266b7c
+				return plainchar - plaintext_out;
Paul Nasrat 266b7c
+			}
Paul Nasrat 266b7c
+			fragment = base64_decode_value(*codechar++);
Paul Nasrat 266b7c
+		} while (fragment < 0);
Paul Nasrat 266b7c
+		*plainchar++ |= (char)((fragment & 0x030) >> 4);
Paul Nasrat 266b7c
+		*plainchar    = (char)((fragment & 0x00f) << 4);
Paul Nasrat 266b7c
+
Paul Nasrat 266b7c
+		do {
Paul Nasrat 266b7c
+			if (codechar == code_in+length_in)
Paul Nasrat 266b7c
+			{
Paul Nasrat 266b7c
+				return plainchar - plaintext_out;
Paul Nasrat 266b7c
+			}
Paul Nasrat 266b7c
+			fragment = base64_decode_value(*codechar++);
Paul Nasrat 266b7c
+		} while (fragment < 0);
Paul Nasrat 266b7c
+		*plainchar++ |= (char)((fragment & 0x03c) >> 2);
Paul Nasrat 266b7c
+		*plainchar    = (char)((fragment & 0x003) << 6);
Paul Nasrat 266b7c
+
Paul Nasrat 266b7c
+		do {
Paul Nasrat 266b7c
+			if (codechar == code_in+length_in)
Paul Nasrat 266b7c
+			{
Paul Nasrat 266b7c
+				return plainchar - plaintext_out;
Paul Nasrat 266b7c
+			}
Paul Nasrat 266b7c
+			fragment = base64_decode_value(*codechar++);
Paul Nasrat 266b7c
+		} while (fragment < 0);
Paul Nasrat 266b7c
+		*plainchar++   |= (char)(fragment & 0x03f);
Paul Nasrat 266b7c
 	}
Paul Nasrat 266b7c
 	/* control should not reach here */
Paul Nasrat 266b7c
 	return plainchar - plaintext_out;