commit c4140c56b7d1d9a29bda32e018e57b2782caa1eb
parent 6ffc52c1ca93c1531ec8454842a0f4e615d58433
Author: Christoph Lohmann <20h@r-36.net>
Date: Sun, 2 Apr 2017 16:25:56 +0200
Base64 as defined in RFC 2045.
Diffstat:
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/base64.c b/base64.c
@@ -11,24 +11,19 @@
#include "ind.h"
char be[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
int
readnwstr(char *buf, char *str, int *p, int max, int l)
{
- int i;
+ int i, j;
for (i = 0; *p < max && i < l; (*p)++) {
- switch (str[*p]) {
- case '\n':
- case '\t':
- case '\r':
- case '\f':
- case ' ':
- break;
- default:
- buf[i++] = str[*p];
- break;
+ for (j = 0; j < strlen(be); j++) {
+ if (str[*p] == be[j]) {
+ buf[i++] = str[*p];
+ break;
+ }
}
}
@@ -80,7 +75,8 @@ b64dec(char *istr, int *len)
char bd[256];
memset(bd, 0x80, 256);
- for (p = 0; p < strlen(be); p++)
+ /* Without »=«. */
+ for (p = 0; p < strlen(be)-1; p++)
bd[(int)be[p]] = p;
bd['='] = 0;