| 124 | } |
| 125 | |
| 126 | bool Base64EncodeBufLen(int64_t in_len, int64_t* out_max) { |
| 127 | // Base64 encoding turns every 3 bytes into 4 characters. If the length is not |
| 128 | // divisible by 3, it pads the input with extra 0 bytes until it is divisible by 3. |
| 129 | // One more character must be allocated to account for Base64Encode's null-padding |
| 130 | // of its output. |
| 131 | *out_max = 1 + 4 * ((in_len + 2) / 3); |
| 132 | if (UNLIKELY(in_len < 0 || |
| 133 | *out_max > static_cast<unsigned>(std::numeric_limits<int>::max()))) { |
| 134 | return false; |
| 135 | } |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | bool Base64Encode(const char* in, int64_t in_len, int64_t out_max, char* out, |
| 140 | unsigned* out_len) { |