| 12 | namespace snap::utils::encoding { |
| 13 | |
| 14 | std::string binaryToBase64(const uint8_t* data, size_t size) { |
| 15 | size_t maxOutSize = 0; |
| 16 | if (size == 0 || EVP_EncodedLength(&maxOutSize, size) != 1 || maxOutSize == 0) { |
| 17 | return ""; |
| 18 | } |
| 19 | |
| 20 | std::string result(maxOutSize, '\0'); |
| 21 | EVP_EncodeBlock(reinterpret_cast<uint8_t*>(result.data()), data, size); |
| 22 | result.resize(result.size() - 1); // remove the trailing \0 that EVP_EncodeBlock always writes |
| 23 | return result; |
| 24 | } |
| 25 | |
| 26 | std::string binaryToBase64(const std::vector<uint8_t>& binary) { |
| 27 | return binaryToBase64(binary.data(), binary.size()); |