| 59 | } |
| 60 | |
| 61 | Status DecodeThreeChars(const char* codes, char* result) { |
| 62 | const uint32 packed = (Convert(codes[0]) << 18) | (Convert(codes[1]) << 12) | |
| 63 | (Convert(codes[2]) << 6) | (Convert(codes[3])); |
| 64 | // Convert() return value has upper 25 bits set if input is invalid. |
| 65 | // Therefore `packed` has high bits set iff at least one of code is invalid. |
| 66 | if (TF_PREDICT_FALSE((packed & 0xFF000000) != 0)) { |
| 67 | return errors::InvalidArgument("Invalid character found in base64."); |
| 68 | } |
| 69 | result[0] = static_cast<char>(packed >> 16); |
| 70 | result[1] = static_cast<char>(packed >> 8); |
| 71 | result[2] = static_cast<char>(packed); |
| 72 | return Status::OK(); |
| 73 | } |
| 74 | } // namespace |
| 75 | |
| 76 | Status Base64Decode(StringPiece data, string* decoded) { |
no test coverage detected