diff options
Diffstat (limited to 'com32/libutil/unbase64.c')
-rw-r--r-- | com32/libutil/unbase64.c | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/com32/libutil/unbase64.c b/com32/libutil/unbase64.c index a1728d10..3cbf3fb4 100644 --- a/com32/libutil/unbase64.c +++ b/com32/libutil/unbase64.c @@ -35,43 +35,42 @@ #include <base64.h> static const unsigned char _base64chars[] = -"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; size_t unbase64(unsigned char *buffer, size_t bufsiz, const char *txt) { - unsigned int bits = 0; - int nbits = 0; - char base64tbl[256]; - int i; - char v; - size_t nbytes = 0; + unsigned int bits = 0; + int nbits = 0; + char base64tbl[256]; + int i; + char v; + size_t nbytes = 0; + memset(base64tbl, -1, sizeof base64tbl); - memset(base64tbl, -1, sizeof base64tbl); - - for ( i = 0 ; _base64chars[i] ; i++ ) { - base64tbl[_base64chars[i]] = i; - } + for (i = 0; _base64chars[i]; i++) { + base64tbl[_base64chars[i]] = i; + } - /* Also support filesystem safe alternate base64 encoding */ - base64tbl['.'] = 62; - base64tbl['-'] = 62; - base64tbl['_'] = 63; + /* Also support filesystem safe alternate base64 encoding */ + base64tbl['.'] = 62; + base64tbl['-'] = 62; + base64tbl['_'] = 63; - while ( *txt ) { - if ( (v = base64tbl[(unsigned char) *txt]) >= 0 ) { - bits <<= 6; - bits += v; - nbits += 6; - if ( nbits >= 8 ) { - if ( nbytes < bufsiz ) - *buffer++ = (bits >> (nbits-8)); - nbytes++; - nbits -= 8; - } + while (*txt) { + if ((v = base64tbl[(unsigned char)*txt]) >= 0) { + bits <<= 6; + bits += v; + nbits += 6; + if (nbits >= 8) { + if (nbytes < bufsiz) + *buffer++ = (bits >> (nbits - 8)); + nbytes++; + nbits -= 8; + } + } + txt++; } - txt++; - } - return nbytes; + return nbytes; } |