summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base64.c22
-rw-r--r--protos.h2
2 files changed, 24 insertions, 0 deletions
diff --git a/base64.c b/base64.c
index 4e772ee1..d942e546 100644
--- a/base64.c
+++ b/base64.c
@@ -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)
diff --git a/protos.h b/protos.h
index 18798f80..68a617e4 100644
--- 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);