diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-04-15 20:01:25 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-04-15 20:01:25 +0200 |
commit | f6e703a938a95c555b388f79966cf955c5d07dc6 (patch) | |
tree | f47eae93adf9f72b1472ced2a1a051e90845dafe /base64.cpp | |
parent | 1ce0bb7ad50129fbab6c0a75f18eee6149ca1be3 (diff) |
HTTP Auth (Basic)
Diffstat (limited to 'base64.cpp')
-rw-r--r-- | base64.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/base64.cpp b/base64.cpp new file mode 100644 index 0000000..3847f0a --- /dev/null +++ b/base64.cpp @@ -0,0 +1,23 @@ +#include "base64.h" + +#include <boost/archive/iterators/binary_from_base64.hpp> +#include <boost/archive/iterators/base64_from_binary.hpp> +#include <boost/archive/iterators/transform_width.hpp> +#include <boost/algorithm/string.hpp> + +std::string decode64(const std::string &val) +{ + using namespace boost::archive::iterators; + using It = transform_width<binary_from_base64<std::string::const_iterator>, 8, 6>; + return boost::algorithm::trim_right_copy_if(std::string(It(std::begin(val)), It(std::end(val))), [](char c) { + return c == '\0'; + }); +} + +std::string encode64(const std::string &val) +{ + using namespace boost::archive::iterators; + using It = base64_from_binary<transform_width<std::string::const_iterator, 6, 8>>; + auto tmp = std::string(It(std::begin(val)), It(std::end(val))); + return tmp.append((3 - val.size() % 3) % 3, '='); +} |