File indexing completed on 2026-05-10 08:44:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_SUPPORT_BASE64_H
0014 #define LLVM_SUPPORT_BASE64_H
0015
0016 #include "llvm/Support/Error.h"
0017 #include <cstdint>
0018 #include <string>
0019 #include <vector>
0020
0021 namespace llvm {
0022
0023 template <class InputBytes> std::string encodeBase64(InputBytes const &Bytes) {
0024 static const char Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
0025 "abcdefghijklmnopqrstuvwxyz"
0026 "0123456789+/";
0027 std::string Buffer;
0028 Buffer.resize(((Bytes.size() + 2) / 3) * 4);
0029
0030 size_t i = 0, j = 0;
0031 for (size_t n = Bytes.size() / 3 * 3; i < n; i += 3, j += 4) {
0032 uint32_t x = ((unsigned char)Bytes[i] << 16) |
0033 ((unsigned char)Bytes[i + 1] << 8) |
0034 (unsigned char)Bytes[i + 2];
0035 Buffer[j + 0] = Table[(x >> 18) & 63];
0036 Buffer[j + 1] = Table[(x >> 12) & 63];
0037 Buffer[j + 2] = Table[(x >> 6) & 63];
0038 Buffer[j + 3] = Table[x & 63];
0039 }
0040 if (i + 1 == Bytes.size()) {
0041 uint32_t x = ((unsigned char)Bytes[i] << 16);
0042 Buffer[j + 0] = Table[(x >> 18) & 63];
0043 Buffer[j + 1] = Table[(x >> 12) & 63];
0044 Buffer[j + 2] = '=';
0045 Buffer[j + 3] = '=';
0046 } else if (i + 2 == Bytes.size()) {
0047 uint32_t x =
0048 ((unsigned char)Bytes[i] << 16) | ((unsigned char)Bytes[i + 1] << 8);
0049 Buffer[j + 0] = Table[(x >> 18) & 63];
0050 Buffer[j + 1] = Table[(x >> 12) & 63];
0051 Buffer[j + 2] = Table[(x >> 6) & 63];
0052 Buffer[j + 3] = '=';
0053 }
0054 return Buffer;
0055 }
0056
0057 llvm::Error decodeBase64(llvm::StringRef Input, std::vector<char> &Output);
0058
0059 }
0060
0061 #endif