| 72 | }; |
| 73 | public: |
| 74 | static std::vector<unsigned char> de(const std::string& base64) { |
| 75 | size_t len = base64.length(); |
| 76 | size_t padding = 0; |
| 77 | if (len > 0 && base64[len - 1] == '=') padding++; |
| 78 | if (len > 1 && base64[len - 2] == '=') padding++; |
| 79 | size_t output_size = (len * 3) / 4 - padding; |
| 80 | std::vector<unsigned char> result; |
| 81 | result.reserve(output_size); |
| 82 | size_t i = 0; |
| 83 | while (i < len) { |
| 84 | int sextets[4] = { 0 }; |
| 85 | int sextet_count = 0; |
| 86 | while (i < len && sextet_count < 4) { |
| 87 | char c = base64[i++]; |
| 88 | if (c <= 127 && kBase64DecodeTable[static_cast<unsigned char>(c)] != -1) { |
| 89 | sextets[sextet_count++] = kBase64DecodeTable[static_cast<unsigned char>(c)]; |
| 90 | } |
| 91 | } |
| 92 | if (sextet_count == 0) continue; |
| 93 | unsigned char triple[3] = { 0 }; |
| 94 | triple[0] = (sextets[0] << 2) | ((sextets[1] & 0x30) >> 4); |
| 95 | triple[1] = ((sextets[1] & 0x0F) << 4) | ((sextets[2] & 0x3C) >> 2); |
| 96 | triple[2] = ((sextets[2] & 0x03) << 6) | sextets[3]; |
| 97 | if (sextet_count >= 2) result.push_back(triple[0]); |
| 98 | if (sextet_count >= 3) result.push_back(triple[1]); |
| 99 | if (sextet_count >= 4) result.push_back(triple[2]); |
| 100 | } |
| 101 | return result; |
| 102 | } |
| 103 | static std::string en(const unsigned char* data, const size_t size) { |
| 104 | if (data == nullptr || size == 0) return {}; |
| 105 | size_t output_len = ((size + 2) / 3) * 4; |
nothing calls this directly
no outgoing calls
no test coverage detected