aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/crypto.c16
-rw-r--r--src/common/crypto.h4
-rw-r--r--src/common/util.c1
3 files changed, 8 insertions, 13 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 3dfe89193..7f0bd899e 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1406,20 +1406,16 @@ base64_decode(char *dest, int destlen, const char *src, int srclen)
}
/** 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 @@ base32_encode(char *dest, int destlen, const char *src, int srclen)
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 @@ int base16_encode(char *dest, int destlen, const char *src, int srclen)
cp += 2;
}
*cp = '\0';
- return 0;
}
static const char HEX_DIGITS[] = "0123456789ABCDEFabcdef";
diff --git a/src/common/crypto.h b/src/common/crypto.h
index 09bb50f05..70ad1bc37 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -92,8 +92,8 @@ int crypto_pk_check_fingerprint_syntax(const char *s);
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 */
diff --git a/src/common/util.c b/src/common/util.c
index 21cb010b3..be4f60028 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1254,6 +1254,7 @@ int check_private_dir(const char *dirname, int create)
{
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,