| 269 | } |
| 270 | |
| 271 | size_t Base64DecodeUneven(void* dst, const TStringBuf s) { |
| 272 | const size_t tailSize = s.length() % 4; |
| 273 | if (tailSize == 0) { |
| 274 | return Base64Decode(dst, s.begin(), s.end()); |
| 275 | } |
| 276 | |
| 277 | // divide s into even part and tail and decode in two step, to avoid memory allocation |
| 278 | char tail[4] = {'=', '=', '=', '='}; |
| 279 | memcpy(tail, s.end() - tailSize, tailSize); |
| 280 | size_t decodedEven = s.length() > 4 ? Base64Decode(dst, s.begin(), s.end() - tailSize) : 0; |
| 281 | // there should not be tail of size 1 it's incorrect for 8-bit bytes |
| 282 | size_t decodedTail = tailSize != 1 ? Base64Decode(static_cast<char*>(dst) + decodedEven, tail, tail + 4) : 0; |
| 283 | return decodedEven + decodedTail; |
| 284 | } |
| 285 | |
| 286 | TString Base64DecodeUneven(const TStringBuf s) { |
| 287 | TString ret; |