diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2016-04-25 12:39:27 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2016-05-04 20:29:05 +0300 |
commit | 7806c39ecc92055cd338749148fda51b2dc01691 (patch) | |
tree | cb52f5bc766d12b68b9d20696aae0b60699ea43a /butl/base64 | |
parent | d20431e11290320f04d62e26b9a7cbcefaf5480c (diff) |
Add base64_encode(), base64_decode()
Diffstat (limited to 'butl/base64')
-rw-r--r-- | butl/base64 | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/butl/base64 b/butl/base64 new file mode 100644 index 0000000..7a0e999 --- /dev/null +++ b/butl/base64 @@ -0,0 +1,48 @@ +// file : butl/base64 -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUTL_BASE64 +#define BUTL_BASE64 + +#include <iosfwd> +#include <string> +#include <vector> + +namespace butl +{ + // Base64-encode a stream or a buffer. Split the output into 76 char-long + // lines (new line is the 77th). If reading from a stream, check if it has + // badbit, failbit, or eofbit set and throw invalid_argument if that's the + // case. Otherwise, set eofbit on completion. If writing to a stream, check + // if it has badbit, failbit, or eofbit set and throw invalid_argument if + // that's the case. Otherwise set badbit if the write operation fails. + // + void + base64_encode (std::ostream&, std::istream&); + + std::string + base64_encode (std::istream&); + + std::string + base64_encode (const std::vector<char>&); + + // Base64-decode a stream or a string. Throw invalid_argument if the input + // is not a valid base64 representation. If reading from a stream, check if + // it has badbit, failbit, or eofbit set and throw invalid_argument if + // that's the case. Otherwise, set eofbit on completion. If writing to a + // stream, check if it has badbit, failbit, or eofbit set and throw + // invalid_argument if that's the case. Otherwise set badbit if the write + // operation fails. + // + void + base64_decode (std::ostream&, std::istream&); + + void + base64_decode (std::ostream&, const std::string&); + + std::vector<char> + base64_decode (const std::string&); +}; + +#endif // BUTL_BASE64 |