| 12 | namespace toft { |
| 13 | |
| 14 | bool Base64::Encode(const StringPiece& input, std::string* output) |
| 15 | { |
| 16 | std::string temp; |
| 17 | temp.resize(modp_b64_encode_len(input.size())); // makes room for null byte |
| 18 | |
| 19 | // null terminates result since result is base64 text! |
| 20 | int input_size = static_cast<int>(input.size()); |
| 21 | int output_size = modp_b64_encode(&(temp[0]), input.data(), input_size); |
| 22 | if (output_size < 0) |
| 23 | return false; |
| 24 | |
| 25 | temp.resize(output_size); // strips off null byte |
| 26 | output->swap(temp); |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | bool Base64::WebSafeEncode(const StringPiece& input, std::string* output) |
| 31 | { |