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

Function base64_encode_impl

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

Source from the content-addressed store, hash-verified

46}
47
48std::string base64_encode_impl(unsigned char const* bytes_to_encode, unsigned int in_len, const char* const b64_chars) {
49
50 std::string ret;
51 int i = 0;
52 int j = 0;
53 unsigned char char_array_3[3];
54 unsigned char char_array_4[4];
55
56 while (in_len--) {
57 char_array_3[i++] = *(bytes_to_encode++);
58 if (i == 3) {
59 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
60 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
61 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
62 char_array_4[3] = char_array_3[2] & 0x3f;
63
64 for(i = 0; (i <4) ; i++)
65 ret += b64_chars[char_array_4[i]];
66 i = 0;
67 }
68 }
69
70 if (i)
71 {
72 for(j = i; j < 3; j++)
73 char_array_3[j] = '\0';
74
75 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
76 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
77 char_array_4[2] = ((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 += b64_chars[char_array_4[j]];
82
83 while((i++ < 3))
84 ret += '=';
85
86 }
87
88 return ret;
89
90}
91
92std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
93 return base64_encode_impl(bytes_to_encode, in_len, base64_chars);

Callers 2

base64_encodeFunction · 0.85
base64url_encodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected