diff options
author | Kevin McCarthy <kevin@8t8.us> | 2019-02-12 15:58:13 -0800 |
---|---|---|
committer | Kevin McCarthy <kevin@8t8.us> | 2019-02-12 18:59:30 -0800 |
commit | 7689f11df45d520eb7b251e3d498c08693493226 (patch) | |
tree | 132326f3d139858cdf002d21526eeb8c00091ebd | |
parent | 912e02a31991d6038eab2105ed701c75f43041d2 (diff) |
Add mutt_buffer helpers for base64 conversion.
Add mutt_buffer_from_base64() mutt_buffer_to_base64() to help with
transitioning to buffers.
-rw-r--r-- | base64.c | 22 | ||||
-rw-r--r-- | protos.h | 2 |
2 files changed, 24 insertions, 0 deletions
@@ -48,6 +48,14 @@ #define BAD -1 +void mutt_buffer_to_base64 (BUFFER *out, const unsigned char *in, size_t len) +{ + mutt_buffer_increase_size (out, + ((len * 2) > LONG_STRING) ? (len * 2) : LONG_STRING); + mutt_to_base64 ((unsigned char *)out->data, in, len, out->dsize); + 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) @@ -79,6 +87,20 @@ void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len, *out = '\0'; } +int mutt_buffer_from_base64 (BUFFER *out, const char *in) +{ + int olen; + + mutt_buffer_increase_size (out, mutt_strlen (in)); + olen = mutt_from_base64 (out->data, in, out->dsize); + if (olen > 0) + out->dptr = out->data + olen; + else + out->dptr = out->data; + + return olen; +} + /* Convert '\0'-terminated base 64 string to raw bytes. * Returns length of returned buffer, or -1 on error */ int mutt_from_base64 (char *out, const char *in, size_t olen) @@ -406,6 +406,8 @@ ADDRESS *alias_reverse_lookup (ADDRESS *); /* base64.c */ void mutt_to_base64 (unsigned char*, const unsigned char*, size_t, size_t); int mutt_from_base64 (char*, const char*, size_t); +void mutt_buffer_to_base64 (BUFFER *, const unsigned char *, size_t); +int mutt_buffer_from_base64 (BUFFER *, const char *); /* utf8.c */ int mutt_wctoutf8 (char *s, unsigned int c, size_t buflen); |