mime: reuse the base64 string from the base64 code

Avoids duplicating an identical string here.

Closes #17309
This commit is contained in:
Daniel Stenberg 2025-05-10 11:12:22 +02:00
parent ff84228a53
commit 674836399f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 14 additions and 13 deletions

View file

@ -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);
}
/*

View file

@ -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 */

View file

@ -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;