From: Daniel Stenberg Date: Sat, 10 May 2025 09:12:22 +0000 (+0200) Subject: mime: reuse the base64 string from the base64 code X-Git-Tag: curl-8_14_0~116 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=674836399fc90315abc3d8c82a2ea6a6a9dc87cd;p=thirdparty%2Fcurl.git mime: reuse the base64 string from the base64 code Avoids duplicating an identical string here. Closes #17309 --- diff --git a/lib/curlx/base64.c b/lib/curlx/base64.c index cadebb4f3e..80624cc296 100644 --- a/lib/curlx/base64.c +++ b/lib/curlx/base64.c @@ -44,7 +44,7 @@ #include "../memdebug.h" /* ---- Base64 Encoding/Decoding Table --- */ -static const char base64encdec[]= +const char Curl_base64encdec[]= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* The Base 64 encoding with a URL and filename safe alphabet, RFC 4648 @@ -257,7 +257,8 @@ static CURLcode base64_encode(const char *table64, CURLcode curlx_base64_encode(const char *inputbuff, size_t insize, char **outptr, size_t *outlen) { - return base64_encode(base64encdec, '=', inputbuff, insize, outptr, outlen); + return base64_encode(Curl_base64encdec, '=', + inputbuff, insize, outptr, outlen); } /* diff --git a/lib/curlx/base64.h b/lib/curlx/base64.h index faa7f71d21..026f80e4d3 100644 --- a/lib/curlx/base64.h +++ b/lib/curlx/base64.h @@ -30,4 +30,7 @@ CURLcode curlx_base64url_encode(const char *inputbuff, size_t insize, char **outptr, size_t *outlen); CURLcode curlx_base64_decode(const char *src, unsigned char **outptr, size_t *outlen); + +extern const char Curl_base64encdec[]; + #endif /* HEADER_CURL_BASE64_H */ diff --git a/lib/mime.c b/lib/mime.c index 1a107b7460..c90c34898d 100644 --- a/lib/mime.c +++ b/lib/mime.c @@ -33,6 +33,7 @@ struct Curl_easy; #include "urldata.h" #include "sendf.h" #include "strdup.h" +#include "curlx/base64.h" #if !defined(CURL_DISABLE_MIME) && (!defined(CURL_DISABLE_HTTP) || \ !defined(CURL_DISABLE_SMTP) || \ @@ -87,10 +88,6 @@ static const struct mime_encoder encoders[] = { {ZERO_NULL, ZERO_NULL, ZERO_NULL} }; -/* Base64 encoding table */ -static const char base64enc[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - /* Quoted-printable character class table. * * We cannot rely on ctype functions since quoted-printable input data @@ -472,10 +469,10 @@ static size_t encoder_base64_read(char *buffer, size_t size, bool ateof, i = st->buf[st->bufbeg++] & 0xFF; i = (i << 8) | (st->buf[st->bufbeg++] & 0xFF); i = (i << 8) | (st->buf[st->bufbeg++] & 0xFF); - *ptr++ = base64enc[(i >> 18) & 0x3F]; - *ptr++ = base64enc[(i >> 12) & 0x3F]; - *ptr++ = base64enc[(i >> 6) & 0x3F]; - *ptr++ = base64enc[i & 0x3F]; + *ptr++ = Curl_base64encdec[(i >> 18) & 0x3F]; + *ptr++ = Curl_base64encdec[(i >> 12) & 0x3F]; + *ptr++ = Curl_base64encdec[(i >> 6) & 0x3F]; + *ptr++ = Curl_base64encdec[i & 0x3F]; cursize += 4; st->pos += 4; size -= 4; @@ -499,10 +496,10 @@ static size_t encoder_base64_read(char *buffer, size_t size, bool ateof, i = (st->buf[st->bufbeg + 1] & 0xFF) << 8; i |= (st->buf[st->bufbeg] & 0xFF) << 16; - ptr[0] = base64enc[(i >> 18) & 0x3F]; - ptr[1] = base64enc[(i >> 12) & 0x3F]; + ptr[0] = Curl_base64encdec[(i >> 18) & 0x3F]; + ptr[1] = Curl_base64encdec[(i >> 12) & 0x3F]; if(++st->bufbeg != st->bufend) { - ptr[2] = base64enc[(i >> 6) & 0x3F]; + ptr[2] = Curl_base64encdec[(i >> 6) & 0x3F]; st->bufbeg++; } cursize += 4;