#51 handle one block encode/decode for base64

This commit is contained in:
Erik Ekman
2009-02-17 20:22:24 +00:00
committed by Erik Ekman
parent aad34d941a
commit eed52b783f
3 changed files with 51 additions and 4 deletions

View File

@@ -95,9 +95,13 @@ base64_encode(char *buf, size_t *buflen, const void *data, size_t size)
}
/* how many chars can we encode within the buf */
maxsize = BLKSIZE_RAW * (*buflen / BLKSIZE_ENC - 1) - 1;
maxsize = BLKSIZE_RAW * (*buflen / BLKSIZE_ENC);
/* how big will the encoded data be */
newsize = BLKSIZE_ENC * (size / BLKSIZE_RAW + 1) + 1;
newsize = BLKSIZE_ENC * (size / BLKSIZE_RAW);
if (size % BLKSIZE_RAW) {
newsize += BLKSIZE_ENC;
}
/* if the buffer is too small, eat some of the data */
if (*buflen < newsize) {
size = maxsize;
@@ -120,7 +124,7 @@ base64_encode(char *buf, size_t *buflen, const void *data, size_t size)
/* store number of bytes from data that was used */
*buflen = size;
return strlen(buf) - 1;
return strlen(buf);
}
#define DECODE_ERROR 0xffffffff

View File

@@ -140,7 +140,7 @@ build_hostname(char *buf, size_t buflen,
size_t space;
char *b;
space = MIN(0xFF, buflen) - strlen(topdomain) - 5;
space = MIN(0xFF, buflen) - strlen(topdomain) - 7;
if (!encoder->places_dots())
space -= (space / 57); /* space for dots */