# HG changeset patch # User reimar # Date 1141830848 0 # Node ID 37bfcf89c89cd16319945dd20d8f97c4f411b274 # Parent 13b2332c515492ff713cd689453e60c9e51e2301 Fix base64 encoding for basic auth according to RFC. Patch by Jeff D'Angelo (jcd+mplayer at psu edu). diff -r 13b2332c5154 -r 37bfcf89c89c libmpdemux/http.c --- a/libmpdemux/http.c Wed Mar 08 15:07:48 2006 +0000 +++ b/libmpdemux/http.c Wed Mar 08 15:14:08 2006 +0000 @@ -659,7 +659,7 @@ int base64_encode(const void *enc, int encLen, char *out, int outMax) { - static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; + static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; unsigned char *encBuf; int outLen; @@ -670,6 +670,7 @@ outLen = 0; bits = 0; shift = 0; + outMax &= ~3; while( outLen0 ) { @@ -685,9 +686,12 @@ bits <<= 6 - shift; shift = 6; } else { - // Terminate with Mime style '=' - *out = '='; - outLen++; + // As per RFC 2045, section 6.8, + // pad output as necessary: 0 to 2 '=' chars. + while( outLen & 3 ){ + *out++ = '='; + outLen++; + } return outLen; }