| 63 | } |
| 64 | |
| 65 | inline bool is_valid_base64_str(const std::string_view encoded_str) { |
| 66 | if ((encoded_str.size() % 4) == 1) { |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | // last two characters can be padding |
| 71 | const auto first_pad = encoded_str.cend() - 2; |
| 72 | const auto second_pad = std::next(first_pad); |
| 73 | |
| 74 | if (!std::all_of(encoded_str.cbegin(), first_pad, is_valid_base64_char)) { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | // two padding characters |
| 79 | if (!is_valid_base64_char(*first_pad)) { |
| 80 | return (*first_pad == '=') && (*second_pad == '='); |
| 81 | } |
| 82 | // one padding or no padding |
| 83 | return is_valid_base64_char(*second_pad) || (*second_pad == '='); |
| 84 | } |
| 85 | |
| 86 | } // anonymous namespace |
| 87 |
no test coverage detected