35 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
37 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
38 -1, -1, -1, -1, -1, -1, -1, 0x3E, -1, -1, -1, 0x3F,
39 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, -1, -1,
40 -1, 0x7F, -1, -1, -1, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
41 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12,
42 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, -1, -1, -1, -1, -1,
43 -1, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
44 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
45 0x31, 0x32, 0x33, -1, -1, -1, -1, -1};
48 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
50 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
52 #define GRPC_BASE64_PAD_CHAR '='
53 #define GRPC_BASE64_PAD_BYTE 0x7F
54 #define GRPC_BASE64_MULTILINE_LINE_LEN 76
55 #define GRPC_BASE64_MULTILINE_NUM_BLOCKS (GRPC_BASE64_MULTILINE_LINE_LEN / 4)
61 size_t result_projected_size =
69 size_t result_projected_size =
70 4 * ((data_size + 3) / 3) +
74 return result_projected_size;
78 int url_safe,
int multiline) {
79 const unsigned char*
data =
static_cast<const unsigned char*
>(vdata);
82 const size_t result_projected_size =
86 size_t num_blocks = 0;
90 while (data_size >= 3) {
108 if (data_size == 2) {
114 }
else if (data_size == 1) {
131 size_t* result_offset) {
134 result[(*result_offset)++] =
static_cast<unsigned char>(packed);
138 size_t* result_offset) {
142 result[(*result_offset)++] =
static_cast<unsigned char>(packed >> 8);
143 result[(*result_offset)++] =
static_cast<unsigned char>(packed);
147 unsigned char*
result,
size_t* result_offset) {
151 if (num_codes == 1) {
155 if (num_codes == 2) {
159 if (num_codes == 3) {
184 result[(*result_offset)++] =
static_cast<unsigned char>(packed >> 16);
185 result[(*result_offset)++] =
static_cast<unsigned char>(packed >> 8);
186 result[(*result_offset)++] =
static_cast<unsigned char>(packed);
195 size_t result_size = 0;
196 unsigned char codes[4];
197 size_t num_codes = 0;
200 unsigned char c =
static_cast<unsigned char>(*b64++);
204 if (
c ==
'+' ||
c ==
'/') {
210 }
else if (
c ==
'_') {
216 if (
c !=
'\r' &&
c !=
'\n') {
221 codes[num_codes++] =
static_cast<unsigned char>(
code);
222 if (num_codes == 4) {
229 if (num_codes != 0 &&