| 99 | |
| 100 | // Decodes into a chunk of memory that is at least as large as the input. |
| 101 | template <typename OutputIter> void decodeBase64(const std::string &encoded, OutputIter out) |
| 102 | { |
| 103 | auto unpadded = encoded; |
| 104 | |
| 105 | const auto num_padded = std::count(begin(encoded), end(encoded), '='); |
| 106 | std::replace(begin(unpadded), end(unpadded), '=', 'A'); // A_64 == \0 |
| 107 | |
| 108 | std::string decoded{detail::BinaryFromBase64{begin(unpadded)}, |
| 109 | detail::BinaryFromBase64{begin(unpadded) + unpadded.length()}}; |
| 110 | |
| 111 | decoded.erase(end(decoded) - num_padded, end(decoded)); |
| 112 | std::copy(begin(decoded), end(decoded), out); |
| 113 | } |
| 114 | |
| 115 | // Convenience specialization, filling string instead of byte-dumping into it. |
| 116 | inline std::string decodeBase64(const std::string &encoded) |
no test coverage detected