Based on https://stackoverflow.com/a/63711162/40645
| 34 | |
| 35 | // Based on https://stackoverflow.com/a/63711162/40645 |
| 36 | string encodeBase64(const unsigned char *input, int n) { |
| 37 | const auto predicted_len = 4 * ((n + 2) / 3); // predict output size |
| 38 | const auto output_buffer{make_unique<char[]>(predicted_len + 1)}; |
| 39 | const auto output_len = EVP_EncodeBlock(reinterpret_cast<unsigned char *>(output_buffer.get()), input, n); |
| 40 | if (predicted_len != static_cast<uint64_t>(output_len)) { |
| 41 | throw runtime_error("base64 encoding error"); |
| 42 | } |
| 43 | return output_buffer.get(); |
| 44 | } |
| 45 | |
| 46 | // Make strings, such as error strings, a little easier on the eyes. |
| 47 | string PrettifySentence(string s) { |