diff options
author | David Robillard <d@drobilla.net> | 2018-05-12 12:47:18 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-05-27 18:23:15 +0200 |
commit | 7953d861d83abd1a30ae2d620a8ba691bdf2ca1d (patch) | |
tree | b07436aa1a1fbef16c9a515ff930d4fa978f93e8 /src/base64.h | |
parent | 2ab12963fd1fb90d254028ff5766afd88a2da54e (diff) | |
download | serd-7953d861d83abd1a30ae2d620a8ba691bdf2ca1d.tar.gz serd-7953d861d83abd1a30ae2d620a8ba691bdf2ca1d.tar.bz2 serd-7953d861d83abd1a30ae2d620a8ba691bdf2ca1d.zip |
Separate base64 implementation
Diffstat (limited to 'src/base64.h')
-rw-r--r-- | src/base64.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/base64.h b/src/base64.h new file mode 100644 index 00000000..b5e04373 --- /dev/null +++ b/src/base64.h @@ -0,0 +1,47 @@ +/* + Copyright 2011-2018 David Robillard <http://drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef SERD_BASE64_H +#define SERD_BASE64_H + +#include "serd/serd.h" + +#include <stdbool.h> +#include <stddef.h> + +/** + 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 Whether to wrap lines at a fixed length. + @return The length of the base64 encoding, exclusing null terminator. +*/ +size_t +serd_base64_get_length(size_t size, bool wrap_lines); + +/** + Encode `size` bytes of `buf` into `str`, which must be large enough. + + @param str Output string buffer. + @param buf Input binary data. + @param size Number of bytes to encode from `buf`. + @param wrap_lines Whether to wrap lines at a fixed length. + @return True iff `str` contains newlines. +*/ +bool +serd_base64_encode(char* str, const void* buf, size_t size, bool wrap_lines); + +#endif // SERD_BASE64_H |