]> granicus.if.org Git - mutt/commitdiff
Add mutt_buffer helpers for base64 conversion.
authorKevin McCarthy <kevin@8t8.us>
Tue, 12 Feb 2019 23:58:13 +0000 (15:58 -0800)
committerKevin McCarthy <kevin@8t8.us>
Wed, 13 Feb 2019 02:59:30 +0000 (18:59 -0800)
Add mutt_buffer_from_base64() mutt_buffer_to_base64() to help with
transitioning to buffers.

base64.c
protos.h

index 4e772ee1b1ae0cdeafff3ec3ae87b5a0e3dc2420..d942e546f42f8b5b75f6af931b5a7f8915093c0a 100644 (file)
--- a/base64.c
+++ b/base64.c
 
 #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)
index 18798f80deebabc12bc868eb7cfb33ec430bc807..68a617e4af27975d130a7b95c4bf0ccf8ad112a2 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -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);