Encodes a chunk of memory to Base64.
| 42 | |
| 43 | // Encodes a chunk of memory to Base64. |
| 44 | inline std::string encodeBase64(const unsigned char *first, std::size_t size) |
| 45 | { |
| 46 | BOOST_ASSERT(size > 0); |
| 47 | |
| 48 | std::string encoded; |
| 49 | encoded.reserve(((size + 2) / 3) * 4); |
| 50 | |
| 51 | auto padding = (3 - size % 3) % 3; |
| 52 | |
| 53 | BOOST_ASSERT(padding == 0 || padding == 1 || padding == 2); |
| 54 | |
| 55 | for (auto itr = detail::Base64FromBinary(first); itr != detail::Base64FromBinary(first + size); |
| 56 | ++itr) |
| 57 | { |
| 58 | encoded.push_back(*itr); |
| 59 | } |
| 60 | |
| 61 | for (size_t index = 0; index < padding; ++index) |
| 62 | { |
| 63 | encoded.push_back('='); |
| 64 | } |
| 65 | |
| 66 | BOOST_ASSERT(encoded.size() == (size + 2) / 3 * 4); |
| 67 | |
| 68 | return encoded; |
| 69 | } |
| 70 | |
| 71 | // C++11 standard 3.9.1/1: Plain char, signed char, and unsigned char are three distinct types |
| 72 |
no test coverage detected