MCPcopy Create free account
hub / github.com/Clarionos/clarion / base64_decode_impl

Function base64_decode_impl

libraries/fc/src/crypto/base64.cpp:110–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110std::string base64_decode_impl(std::string const& encoded_string, const char* const b64_chars) {
111 int in_len = encoded_string.size();
112 int i = 0;
113 int j = 0;
114 int in_ = 0;
115 unsigned char char_array_4[4], char_array_3[3];
116 std::string ret;
117
118 while (in_len-- && encoded_string[in_] != '=') {
119 throw_on_nonbase64(encoded_string[in_], b64_chars);
120 char_array_4[i++] = encoded_string[in_]; in_++;
121 if (i ==4) {
122 for (i = 0; i <4; i++)
123 char_array_4[i] = strchr(b64_chars, char_array_4[i]) - b64_chars;
124
125 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
126 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
127 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
128
129 for (i = 0; (i < 3); i++)
130 ret += char_array_3[i];
131 i = 0;
132 }
133 }
134
135 if (i) {
136 for (j = i; j <4; j++)
137 char_array_4[j] = 0;
138
139 for (j = 0; j <4; j++)
140 char_array_4[j] = strchr(b64_chars, char_array_4[j]) - b64_chars;
141
142 char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
143 char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
144 char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
145
146 for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
147 }
148
149 return ret;
150}
151
152std::string base64_decode(std::string const& encoded_string) {
153 return base64_decode_impl(encoded_string, base64_chars);

Callers 2

base64_decodeFunction · 0.85
base64url_decodeFunction · 0.85

Calls 2

throw_on_nonbase64Function · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected