Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 #ifndef base64_DEFINED | |
| 8 #define base64_DEFINED | |
| 9 | |
| 10 #include <stdio.h> | |
| 11 | |
| 12 inline void EncodeToBase64(const void* data, size_t size, FILE* out) { | |
|
mtklein
2015/09/17 13:58:22
Ditto. Why is this not in fiddle_main?
| |
| 13 const uint8_t* input = reinterpret_cast<const uint8_t*>(data); | |
| 14 const uint8_t* end = &input[size]; | |
| 15 static const char codes[] = | |
| 16 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| 17 "abcdefghijklmnopqrstuvwxyz0123456789+/"; | |
| 18 while (input != end) { | |
| 19 uint8_t b = (*input & 0xFC) >> 2; | |
| 20 fputc(codes[b], out); | |
| 21 b = (*input & 0x03) << 4; | |
| 22 ++input; | |
| 23 if (input == end) { | |
| 24 fputc(codes[b], out); | |
| 25 fputs("==", out); | |
| 26 return; | |
| 27 } | |
| 28 b |= (*input & 0xF0) >> 4; | |
| 29 fputc(codes[b], out); | |
| 30 b = (*input & 0x0F) << 2; | |
| 31 ++input; | |
| 32 if (input == end) { | |
| 33 fputc(codes[b], out); | |
| 34 fputc('=', out); | |
| 35 return; | |
| 36 } | |
| 37 b |= (*input & 0xC0) >> 6; | |
| 38 fputc(codes[b], out); | |
| 39 b = *input & 0x3F; | |
| 40 fputc(codes[b], out); | |
| 41 ++input; | |
| 42 } | |
| 43 } | |
| 44 #endif // base64_DEFINED | |
| OLD | NEW |