| 29 | = (const uint8_t*)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
| 30 | |
| 31 | void base64_encode(const uint8_t* in, uint32_t len, uint8_t* buf) { |
| 32 | buf[0] = kBase64EncodeTable[(in[0] >> 2) & 0x3f]; |
| 33 | if (len == 3) { |
| 34 | buf[1] = kBase64EncodeTable[((in[0] << 4) & 0x30) | ((in[1] >> 4) & 0x0f)]; |
| 35 | buf[2] = kBase64EncodeTable[((in[1] << 2) & 0x3c) | ((in[2] >> 6) & 0x03)]; |
| 36 | buf[3] = kBase64EncodeTable[in[2] & 0x3f]; |
| 37 | } else if (len == 2) { |
| 38 | buf[1] = kBase64EncodeTable[((in[0] << 4) & 0x30) | ((in[1] >> 4) & 0x0f)]; |
| 39 | buf[2] = kBase64EncodeTable[(in[1] << 2) & 0x3c]; |
| 40 | } else { // len == 1 |
| 41 | buf[1] = kBase64EncodeTable[(in[0] << 4) & 0x30]; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | static const uint8_t kBase64DecodeTable[256] = { |
| 46 | 0xff, |
no outgoing calls