aboutsummaryrefslogtreecommitdiffstats
path: root/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-03-17 23:49:10 +0100
committerDavid Robillard <d@drobilla.net>2019-04-13 19:15:32 +0200
commitdd7f57a7d955a323c5691ec64dd96e9b0a5a2553 (patch)
tree58f62490c75c52891d900139aa630bbd04d1e979 /serd
parent14c2fe14b90c1057b2829b7008423ef9bf79edef (diff)
downloadserd-dd7f57a7d955a323c5691ec64dd96e9b0a5a2553.tar.gz
serd-dd7f57a7d955a323c5691ec64dd96e9b0a5a2553.tar.bz2
serd-dd7f57a7d955a323c5691ec64dd96e9b0a5a2553.zip
Clean up and expose base64 implementation
Diffstat (limited to 'serd')
-rw-r--r--serd/serd.h49
1 files changed, 45 insertions, 4 deletions
diff --git a/serd/serd.h b/serd/serd.h
index e764d069..d87896ea 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -378,18 +378,59 @@ double
serd_strtod(const char* str, size_t* end);
/**
+ @}
+ @name Base64
+ @{
+*/
+
+/**
+ Return the number of bytes required to encode `size` bytes in base64.
+
+ @param size The number of input (binary) bytes to encode.
+ @param wrap_lines Wrap lines at 76 characters to conform to RFC 2045.
+ @return The length of the base64 encoding, excluding null terminator.
+*/
+SERD_API
+size_t
+serd_base64_encoded_length(size_t size, bool wrap_lines);
+
+/**
+ Return the maximum number of bytes required to decode `size` bytes of base64.
+
+ @param len The number of input (text) bytes to decode.
+ @return The required buffer size to decode `size` bytes of base64.
+*/
+SERD_API
+size_t
+serd_base64_decoded_size(size_t len);
+
+/**
+ Encode `size` bytes of `buf` into `str`, which must be large enough.
+
+ @param str Output buffer of at least serd_base64_encoded_length(size) bytes.
+ @param buf Input binary data.
+ @param size Number of bytes to encode from `buf`.
+ @param wrap_lines Wrap lines at 76 characters to conform to RFC 2045.
+ @return True iff `str` contains newlines.
+*/
+SERD_API
+bool
+serd_base64_encode(char* str, const void* buf, size_t size, bool wrap_lines);
+
+/**
Decode a base64 string.
+
This function can be used to deserialise a blob node created with
serd_new_blob().
+ @param buf Output buffer of at least serd_base64_decoded_size(size) bytes.
+ @param size Set to the size of the decoded data in bytes.
@param str Base64 string to decode.
@param len The length of `str`.
- @param size Set to the size of the returned blob in bytes.
- @return A newly allocated blob which must be freed with serd_free().
*/
SERD_API
-void*
-serd_base64_decode(const char* str, size_t len, size_t* size);
+SerdStatus
+serd_base64_decode(void* buf, size_t* size, const char* str, size_t len);
/**
@}