| 40 | } |
| 41 | |
| 42 | bool base64ToBinaryInternal(const char* encodedString, size_t inSize, std::vector<uint8_t>* ret) { |
| 43 | // Strip out newlines since the decoder returns an error code (0) if it finds them within the encoded string. |
| 44 | std::string noNewlines(encodedString, inSize); |
| 45 | boost::algorithm::replace_all(noNewlines, "\n", ""); |
| 46 | boost::algorithm::replace_all(noNewlines, "\r", ""); |
| 47 | |
| 48 | // Determine the max array length we'll need given the string length |
| 49 | size_t maxOutSize = 0; |
| 50 | if (EVP_DecodedLength(&maxOutSize, noNewlines.length()) != 1 || maxOutSize == 0) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | ret->resize(maxOutSize); |
| 55 | size_t outSize = 0; |
| 56 | if (EVP_DecodeBase64(reinterpret_cast<uint8_t*>(ret->data()), |
| 57 | &outSize, |
| 58 | maxOutSize, |
| 59 | reinterpret_cast<const uint8_t*>(noNewlines.c_str()), |
| 60 | noNewlines.length()) != 1) { |
| 61 | // make it empty to indicate error |
| 62 | ret->resize(0); |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | ret->resize(outSize); |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | std::vector<uint8_t> base64ToBinary(std::string_view base64) { |
| 71 | std::vector<uint8_t> decodedData; |
no test coverage detected