diff options
author | Roger Dingledine <arma@torproject.org> | 2004-07-22 08:30:06 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-07-22 08:30:06 +0000 |
commit | 7459d067a5b158f39ac8ff9a90ce6059e91d4302 (patch) | |
tree | 74501e22937458399ab1d98939a2261d60a57e8d /src/common/crypto.c | |
parent | ea43172c11af49dcf770fdcbcf80fcbef3437c19 (diff) | |
download | tor-7459d067a5b158f39ac8ff9a90ce6059e91d4302.tar.gz tor-7459d067a5b158f39ac8ff9a90ce6059e91d4302.zip |
now base16_encode() and base32_encode() can't ever fail
svn:r2103
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r-- | src/common/crypto.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 3dfe891932..7f0bd899e3 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"; |