Loading lib/base64.c +40 −45 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ #include "memdebug.h" #endif static void decodeQuantum(unsigned char *dest, char *src) static void decodeQuantum(unsigned char *dest, const char *src) { unsigned int x = 0; int i; Loading @@ -70,18 +70,20 @@ static void decodeQuantum(unsigned char *dest, char *src) dest[0] = (unsigned char)(x & 255); x >>= 8; } /* base64Decode * Given a base64 string at src, decode it into the memory pointed * to by dest. If rawLength points to a valid address (ie not NULL), * store the length of the decoded data to it. /* * Curl_base64_decode() * * Given a base64 string at src, decode it into the memory pointed to by * dest. Returns the length of the decoded data. */ static void base64Decode(unsigned char *dest, char *src, int *rawLength) size_t Curl_base64_decode(char *dest, const char *src) { int length = 0; int equalsTerm = 0; int i; int numQuantums; unsigned char lastQuantum[3]; size_t rawlen=0; while((src[length] != '=') && src[length]) length++; Loading @@ -89,11 +91,11 @@ static void base64Decode(unsigned char *dest, char *src, int *rawLength) equalsTerm++; numQuantums = (length + equalsTerm) / 4; if(rawLength) *rawLength = (numQuantums * 3) - equalsTerm; rawlen = (numQuantums * 3) - equalsTerm; for(i = 0; i < numQuantums - 1; i++) { decodeQuantum(dest, src); decodeQuantum((unsigned char *)dest, src); dest += 3; src += 4; } Loading @@ -101,6 +103,7 @@ static void base64Decode(unsigned char *dest, char *src, int *rawLength) for(i = 0; i < 3 - equalsTerm; i++) dest[i] = lastQuantum[i]; return rawlen; } /* ---- Base64 Encoding --- */ Loading @@ -115,7 +118,7 @@ static char table64[]= * went wrong, -1 is returned. * */ int Curl_base64_encode(const void *inp, size_t insize, char **outptr) size_t Curl_base64_encode(const char *inp, size_t insize, char **outptr) { unsigned char ibuf[3]; unsigned char obuf[4]; Loading @@ -131,7 +134,7 @@ int Curl_base64_encode(const void *inp, size_t insize, char **outptr) base64data = output = (char*)malloc(insize*4/3+4); if(NULL == output) return -1; return 0; while(insize > 0) { for (i = inputparts = 0; i < 3; i++) { Loading Loading @@ -179,14 +182,6 @@ int Curl_base64_encode(const void *inp, size_t insize, char **outptr) } /* ---- End of Base64 Encoding ---- */ int Curl_base64_decode(const char *str, void *data) { int ret; base64Decode((unsigned char *)data, (char *)str, &ret); return ret; } /************* TEST HARNESS STUFF ****************/ Loading lib/base64.h +2 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,6 @@ * * $Id$ ***************************************************************************/ int Curl_base64_encode(const void *data, size_t size, char **str); int Curl_base64_decode(const char *str, void *data); size_t Curl_base64_encode(const char *input, size_t size, char **str); size_t Curl_base64_decode(char *dest, const char *source); #endif lib/http.c +2 −2 Original line number Diff line number Diff line Loading @@ -127,7 +127,7 @@ static CURLcode Curl_output_basic(struct connectdata *conn) sprintf(data->state.buffer, "%s:%s", conn->user, conn->passwd); if(Curl_base64_encode(data->state.buffer, strlen(data->state.buffer), &authorization) >= 0) { &authorization) > 0) { if(conn->allocptr.userpwd) free(conn->allocptr.userpwd); conn->allocptr.userpwd = aprintf( "Authorization: Basic %s\015\012", Loading @@ -147,7 +147,7 @@ static CURLcode Curl_output_basic_proxy(struct connectdata *conn) sprintf(data->state.buffer, "%s:%s", conn->proxyuser, conn->proxypasswd); if(Curl_base64_encode(data->state.buffer, strlen(data->state.buffer), &authorization) >= 0) { &authorization) > 0) { Curl_safefree(conn->allocptr.proxyuserpwd); conn->allocptr.proxyuserpwd = aprintf("Proxy-authorization: Basic %s\015\012", authorization); Loading Loading
lib/base64.c +40 −45 Original line number Diff line number Diff line Loading @@ -46,7 +46,7 @@ #include "memdebug.h" #endif static void decodeQuantum(unsigned char *dest, char *src) static void decodeQuantum(unsigned char *dest, const char *src) { unsigned int x = 0; int i; Loading @@ -70,18 +70,20 @@ static void decodeQuantum(unsigned char *dest, char *src) dest[0] = (unsigned char)(x & 255); x >>= 8; } /* base64Decode * Given a base64 string at src, decode it into the memory pointed * to by dest. If rawLength points to a valid address (ie not NULL), * store the length of the decoded data to it. /* * Curl_base64_decode() * * Given a base64 string at src, decode it into the memory pointed to by * dest. Returns the length of the decoded data. */ static void base64Decode(unsigned char *dest, char *src, int *rawLength) size_t Curl_base64_decode(char *dest, const char *src) { int length = 0; int equalsTerm = 0; int i; int numQuantums; unsigned char lastQuantum[3]; size_t rawlen=0; while((src[length] != '=') && src[length]) length++; Loading @@ -89,11 +91,11 @@ static void base64Decode(unsigned char *dest, char *src, int *rawLength) equalsTerm++; numQuantums = (length + equalsTerm) / 4; if(rawLength) *rawLength = (numQuantums * 3) - equalsTerm; rawlen = (numQuantums * 3) - equalsTerm; for(i = 0; i < numQuantums - 1; i++) { decodeQuantum(dest, src); decodeQuantum((unsigned char *)dest, src); dest += 3; src += 4; } Loading @@ -101,6 +103,7 @@ static void base64Decode(unsigned char *dest, char *src, int *rawLength) for(i = 0; i < 3 - equalsTerm; i++) dest[i] = lastQuantum[i]; return rawlen; } /* ---- Base64 Encoding --- */ Loading @@ -115,7 +118,7 @@ static char table64[]= * went wrong, -1 is returned. * */ int Curl_base64_encode(const void *inp, size_t insize, char **outptr) size_t Curl_base64_encode(const char *inp, size_t insize, char **outptr) { unsigned char ibuf[3]; unsigned char obuf[4]; Loading @@ -131,7 +134,7 @@ int Curl_base64_encode(const void *inp, size_t insize, char **outptr) base64data = output = (char*)malloc(insize*4/3+4); if(NULL == output) return -1; return 0; while(insize > 0) { for (i = inputparts = 0; i < 3; i++) { Loading Loading @@ -179,14 +182,6 @@ int Curl_base64_encode(const void *inp, size_t insize, char **outptr) } /* ---- End of Base64 Encoding ---- */ int Curl_base64_decode(const char *str, void *data) { int ret; base64Decode((unsigned char *)data, (char *)str, &ret); return ret; } /************* TEST HARNESS STUFF ****************/ Loading
lib/base64.h +2 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,6 @@ * * $Id$ ***************************************************************************/ int Curl_base64_encode(const void *data, size_t size, char **str); int Curl_base64_decode(const char *str, void *data); size_t Curl_base64_encode(const char *input, size_t size, char **str); size_t Curl_base64_decode(char *dest, const char *source); #endif
lib/http.c +2 −2 Original line number Diff line number Diff line Loading @@ -127,7 +127,7 @@ static CURLcode Curl_output_basic(struct connectdata *conn) sprintf(data->state.buffer, "%s:%s", conn->user, conn->passwd); if(Curl_base64_encode(data->state.buffer, strlen(data->state.buffer), &authorization) >= 0) { &authorization) > 0) { if(conn->allocptr.userpwd) free(conn->allocptr.userpwd); conn->allocptr.userpwd = aprintf( "Authorization: Basic %s\015\012", Loading @@ -147,7 +147,7 @@ static CURLcode Curl_output_basic_proxy(struct connectdata *conn) sprintf(data->state.buffer, "%s:%s", conn->proxyuser, conn->proxypasswd); if(Curl_base64_encode(data->state.buffer, strlen(data->state.buffer), &authorization) >= 0) { &authorization) > 0) { Curl_safefree(conn->allocptr.proxyuserpwd); conn->allocptr.proxyuserpwd = aprintf("Proxy-authorization: Basic %s\015\012", authorization); Loading