| 119 | } |
| 120 | |
| 121 | static inline void Base64Encode(const char* in, int in_len, std::ostringstream* out) { |
| 122 | typedef base64_from_binary<transform_width<const char*, 6, 8> > base64_encode; |
| 123 | // Base64 encodes 8 byte chars as 6 bit values. |
| 124 | std::ostringstream::pos_type len_before = out->tellp(); |
| 125 | copy(base64_encode(in), base64_encode(in + in_len), std::ostream_iterator<char>(*out)); |
| 126 | int bytes_written = out->tellp() - len_before; |
| 127 | // Pad with = to make it valid base64 encoded string |
| 128 | int num_pad = bytes_written % 4; |
| 129 | if (num_pad != 0) { |
| 130 | num_pad = 4 - num_pad; |
| 131 | for (int i = 0; i < num_pad; ++i) { |
| 132 | (*out) << "="; |
| 133 | } |
| 134 | } |
| 135 | DCHECK_EQ(out->str().size() % 4, 0); |
| 136 | } |
| 137 | |
| 138 | void Base64Encode(const vector<uint8_t>& in, string* out) { |
| 139 | if (in.empty()) { |