diff options
author | Sebastian Andrzej Siewior <sebastian@breakpoint.cc> | 2023-03-04 18:33:35 +0100 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2023-03-04 18:11:15 -0800 |
commit | 5df86199463b5cf893fb6a37457fa02804d3b02a (patch) | |
tree | 3e3bc9bdf4449d94bfbc3c19d608e1673be9d224 /base64.c | |
parent | cecddeac3be3d37a3418f01a02c9c0fbdd9f6d8c (diff) |
Use base64 URL safe alphabet for message id generation.
The character '/' from base64 alphabet breaks web redirectors if the
message-id from an email is used as part of the URL for redirectors and/
or automatic pointers to an email.
Use the URL safe alphabet from RFC4648 section 5 for message id
generation.
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Diffstat (limited to 'base64.c')
-rw-r--r-- | base64.c | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -56,16 +56,15 @@ void mutt_buffer_to_base64 (BUFFER *out, const unsigned char *in, size_t len) mutt_buffer_fix_dptr (out); } -/* raw bytes to null-terminated base 64 string */ -void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len, - size_t olen) +static void to_base64 (unsigned char *out, const unsigned char *in, size_t len, + size_t olen, const char *dict) { while (len >= 3 && olen > 4) { - *out++ = B64Chars[in[0] >> 2]; - *out++ = B64Chars[((in[0] << 4) & 0x30) | (in[1] >> 4)]; - *out++ = B64Chars[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; - *out++ = B64Chars[in[2] & 0x3f]; + *out++ = dict[in[0] >> 2]; + *out++ = dict[((in[0] << 4) & 0x30) | (in[1] >> 4)]; + *out++ = dict[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; + *out++ = dict[in[2] & 0x3f]; olen -= 4; len -= 3; in += 3; @@ -76,15 +75,29 @@ void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len, { unsigned char fragment; - *out++ = B64Chars[in[0] >> 2]; + *out++ = dict[in[0] >> 2]; fragment = (in[0] << 4) & 0x30; if (len > 1) fragment |= in[1] >> 4; - *out++ = B64Chars[fragment]; - *out++ = (len < 2) ? '=' : B64Chars[(in[1] << 2) & 0x3c]; + *out++ = dict[fragment]; + *out++ = (len < 2) ? '=' : dict[(in[1] << 2) & 0x3c]; *out++ = '='; } *out = '\0'; + +} + +/* raw bytes to null-terminated base 64 string */ +void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len, + size_t olen) +{ + to_base64 (out, in, len, olen, B64Chars); +} + +void mutt_to_base64_safeurl (unsigned char *out, const unsigned char *in, + size_t len, size_t olen) +{ + to_base64 (out, in, len, olen, B64Chars_urlsafe); } int mutt_buffer_from_base64 (BUFFER *out, const char *in) |