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

[or-cvs] now base16_encode() and base32_encode() can"t ever fail



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/common

Modified Files:
	crypto.c crypto.h util.c 
Log Message:
now base16_encode() and base32_encode() can't ever fail


Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -d -r1.98 -r1.99
--- crypto.c	21 Jul 2004 22:34:32 -0000	1.98
+++ crypto.c	22 Jul 2004 08:29:07 -0000	1.99
@@ -1406,20 +1406,16 @@
 }
 
 /** Implements base32 encoding as in rfc3548.  Limitation: Requires
- * that srclen is a multiple of 5.
+ * that srclen*8 is a multiple of 5.
  */
-int
+void
 base32_encode(char *dest, int destlen, const char *src, int srclen)
 {
   int nbits, i, bit, v, u;
   nbits = srclen * 8;
 
-  if ((nbits%5) != 0)
-    /* We need an even multiple of 5 bits. */
-    return -1;
-  if ((nbits/5)+1 > destlen)
-    /* Not enough space. */
-    return -1;
+  tor_assert((nbits%5) == 0); /* We need an even multiple of 5 bits. */
+  tor_assert((nbits/5)+1 <= destlen); /* We need enough space. */
 
   for (i=0,bit=0; bit < nbits; ++i, bit+=5) {
     /* set v to the 16-bit value starting at src[bits/8], 0-padded. */
@@ -1430,10 +1426,9 @@
     dest[i] = BASE32_CHARS[u];
   }
   dest[i] = '\0';
-  return 0;
 }
 
-int base16_encode(char *dest, int destlen, const char *src, int srclen)
+void base16_encode(char *dest, int destlen, const char *src, int srclen)
 {
   const char *end;
   char *cp;
@@ -1448,7 +1443,6 @@
     cp += 2;
   }
   *cp = '\0';
-  return 0;
 }
 
 static const char HEX_DIGITS[] = "0123456789ABCDEFabcdef";

Index: crypto.h
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.h,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- crypto.h	1 Jul 2004 01:16:58 -0000	1.49
+++ crypto.h	22 Jul 2004 08:29:07 -0000	1.50
@@ -92,8 +92,8 @@
 int base64_encode(char *dest, int destlen, const char *src, int srclen);
 int base64_decode(char *dest, int destlen, const char *src, int srclen);
 #define BASE32_CHARS "abcdefghijklmnopqrstuvwxyz234567"
-int base32_encode(char *dest, int destlen, const char *src, int srclen);
-int base16_encode(char *dest, int destlen, const char *src, int srclen);
+void base32_encode(char *dest, int destlen, const char *src, int srclen);
+void base16_encode(char *dest, int destlen, const char *src, int srclen);
 int base16_decode(char *dest, int destlen, const char *src, int srclen);
 
 /* Key negotiation */

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -d -r1.114 -r1.115
--- util.c	20 Jul 2004 21:23:50 -0000	1.114
+++ util.c	22 Jul 2004 08:29:07 -0000	1.115
@@ -1254,6 +1254,7 @@
 {
   int r;
   struct stat st;
+  tor_assert(dirname);
   if (stat(dirname, &st)) {
     if (errno != ENOENT) {
       log(LOG_WARN, "Directory %s cannot be read: %s", dirname,