[dovecot-cvs] dovecot/src/lib base64.c, 1.9, 1.10 base64.h, 1.9, 1.10 sha1.c, 1.2, 1.3 sha1.h, 1.3, 1.4

cras at dovecot.org cras at dovecot.org
Wed Sep 15 16:19:49 EEST 2004


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv22403

Modified Files:
	base64.c base64.h sha1.c sha1.h 
Log Message:
Change src from unsigned char* toi void* so callers don't have to do
casting always.



Index: base64.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/base64.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- base64.c	5 Jan 2003 13:09:51 -0000	1.9
+++ base64.c	15 Sep 2004 13:19:47 -0000	1.10
@@ -46,17 +46,18 @@
 static const char basis_64[] =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
-int base64_encode(const unsigned char *src, size_t src_size, buffer_t *dest)
+int base64_encode(const void *src, size_t src_size, buffer_t *dest)
 {
+	const unsigned char *src_c = src;
 	size_t src_pos;
 	int c1, c2, c3;
 
 	for (src_pos = 0; src_pos < src_size; ) {
-		c1 = src[src_pos++];
+		c1 = src_c[src_pos++];
 		if (buffer_append_c(dest, basis_64[c1 >> 2]) != 1)
 			return 0;
 
-		c2 = src_pos == src_size ? 0 : src[src_pos];
+		c2 = src_pos == src_size ? 0 : src_c[src_pos];
 		if (buffer_append_c(dest, basis_64[((c1 & 0x03) << 4) |
 						   ((c2 & 0xf0) >> 4)]) != 1)
 			return 0;
@@ -67,7 +68,7 @@
 			break;
 		}
 
-		c3 = src_pos == src_size ? 0 : src[src_pos];
+		c3 = src_pos == src_size ? 0 : src_c[src_pos];
 		if (buffer_append_c(dest, basis_64[((c2 & 0x0f) << 2) |
 						   ((c3 & 0xc0) >> 6)]) != 1)
 			return 0;
@@ -107,16 +108,17 @@
     XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
 };
 
-int base64_decode(const unsigned char *src, size_t src_size,
+int base64_decode(const void *src, size_t src_size,
 		  size_t *src_pos_r, buffer_t *dest)
 {
+	const unsigned char *src_c = src;
 	size_t src_pos;
 	unsigned char buf[4];
 	int c1, c2, c3, c4;
 	size_t ret, size;
 
 	for (src_pos = 0; src_pos+3 < src_size; ) {
-		c1 = src[src_pos++];
+		c1 = src_c[src_pos++];
 
 		if (c1 == '\n' || c1 == '\r' || c1 == ' ' || c1 == '\t')
 			continue;
@@ -124,15 +126,15 @@
 		if (index_64[c1] == XX)
 			return -1;
 
-		c2 = src[src_pos++];
+		c2 = src_c[src_pos++];
 		if (index_64[c2] == XX)
 			return -1;
 
-		c3 = src[src_pos++];
+		c3 = src_c[src_pos++];
 		if (c3 != '=' && index_64[c3] == XX)
 			return -1;
 
-		c4 = src[src_pos++];
+		c4 = src_c[src_pos++];
 		if (c4 != '=' && index_64[c4] == XX)
 			return -1;
 

Index: base64.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/base64.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- base64.h	5 Jan 2003 13:09:51 -0000	1.9
+++ base64.h	15 Sep 2004 13:19:47 -0000	1.10
@@ -3,7 +3,7 @@
 
 /* Translates binary data into base64. The src must not point to dest buffer.
    Returns 1 if all ok, 0 if dest buffer got full. */
-int base64_encode(const unsigned char *src, size_t src_size, buffer_t *dest);
+int base64_encode(const void *src, size_t src_size, buffer_t *dest);
 
 /* Translates base64 data into binary and appends it to dest buffer. dest may
    point to same buffer as src. Returns 1 if all ok, 0 if dest buffer got full
@@ -13,7 +13,7 @@
    This function may be called multiple times for parsing the same stream.
    If src_pos is non-NULL, it's updated to first non-translated character in
    src. */
-int base64_decode(const unsigned char *src, size_t src_size,
+int base64_decode(const void *src, size_t src_size,
 		  size_t *src_pos_r, buffer_t *dest);
 
 /* max. buffer size required for base64_encode() */

Index: sha1.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/sha1.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- sha1.c	30 Jul 2004 02:58:22 -0000	1.2
+++ sha1.c	15 Sep 2004 13:19:47 -0000	1.3
@@ -212,8 +212,9 @@
 }
 
 void
-sha1_loop(struct sha1_ctxt *ctxt, const uint8_t *input, size_t len)
+sha1_loop(struct sha1_ctxt *ctxt, const void *input, size_t len)
 {
+	const unsigned char *input_c = input;
 	size_t gaplen;
 	size_t gapstart;
 	size_t off;
@@ -226,7 +227,7 @@
 		gaplen = 64 - gapstart;
 
 		copysiz = (gaplen < len - off) ? gaplen : len - off;
-		memmove(&ctxt->m.b8[gapstart], &input[off], copysiz);
+		memmove(&ctxt->m.b8[gapstart], &input_c[off], copysiz);
 		COUNT += copysiz;
 		COUNT %= 64;
 		ctxt->c.b64[0] += copysiz * 8;

Index: sha1.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/sha1.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- sha1.h	30 Jul 2004 02:58:59 -0000	1.3
+++ sha1.h	15 Sep 2004 13:19:47 -0000	1.4
@@ -56,7 +56,7 @@
 
 extern void sha1_init(struct sha1_ctxt *);
 extern void sha1_pad(struct sha1_ctxt *);
-extern void sha1_loop(struct sha1_ctxt *, const uint8_t *, size_t);
+extern void sha1_loop(struct sha1_ctxt *, const void *, size_t);
 extern void sha1_result(struct sha1_ctxt *, void *);
 
 



More information about the dovecot-cvs mailing list