MCPcopy Create free account
hub / github.com/alibaba/async_simple / base64_encode

Function base64_encode

demo_example/smtp/smtp_client.cpp:44–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44std::string base64_encode(const std::string &str) {
45 std::string ret;
46 int i = 0;
47 int j = 0;
48 char char_array_3[3];
49 char char_array_4[4];
50
51 auto bytes_to_encode = str.data();
52 size_t in_len = str.size();
53 while (in_len--) {
54 char_array_3[i++] = *(bytes_to_encode++);
55 if (i == 3) {
56 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
57 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) +
58 ((char_array_3[1] & 0xf0) >> 4);
59 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) +
60 ((char_array_3[2] & 0xc0) >> 6);
61 char_array_4[3] = char_array_3[2] & 0x3f;
62
63 for (i = 0; (i < 4); i++)
64 ret += base64_chars[char_array_4[i]];
65 i = 0;
66 }
67 }
68
69 if (i) {
70 for (j = i; j < 3; j++)
71 char_array_3[j] = '\0';
72
73 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
74 char_array_4[1] =
75 ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
76 char_array_4[2] =
77 ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
78 char_array_4[3] = char_array_3[2] & 0x3f;
79
80 for (j = 0; (j < i + 1); j++)
81 ret += base64_chars[char_array_4[j]];
82
83 while ((i++ < 3))
84 ret += '=';
85 }
86
87 return ret;
88}
89std::string base64_decode(std::string const &encoded_string) {
90 int in_len = encoded_string.size();
91 int i = 0;

Callers 2

build_smtp_fileMethod · 0.85
build_requestMethod · 0.85

Calls 2

dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected