diff options
author | David Robillard <d@drobilla.net> | 2019-03-17 23:49:10 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-12-19 20:57:52 -0500 |
commit | 7aaf7d5187ded5c726ff23ec58b2f8a3d5d158b2 (patch) | |
tree | e90da3ee89cac469041fff0fdb4d393724946489 /serd | |
parent | f03a9cffc2f52d637692210e2a3e96f545972976 (diff) | |
download | serd-7aaf7d5187ded5c726ff23ec58b2f8a3d5d158b2.tar.gz serd-7aaf7d5187ded5c726ff23ec58b2f8a3d5d158b2.tar.bz2 serd-7aaf7d5187ded5c726ff23ec58b2f8a3d5d158b2.zip |
Clean up and expose base64 implementation
Diffstat (limited to 'serd')
-rw-r--r-- | serd/serd.h | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/serd/serd.h b/serd/serd.h index 1dc4db97..dfd53480 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -361,18 +361,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); /** @} |