MCPcopy Create free account
hub / github.com/LUX-Core/lux / EncodeBase64

Function EncodeBase64

src/utilstrencodings.cpp:98–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98string EncodeBase64(const unsigned char* pch, size_t len)
99{
100 static const char* pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
101
102 string strRet = "";
103 strRet.reserve((len + 2) / 3 * 4);
104
105 int mode = 0, left = 0;
106 const unsigned char* pchEnd = pch + len;
107
108 while (pch < pchEnd) {
109 int enc = *(pch++);
110 switch (mode) {
111 case 0: // we have no bits
112 strRet += pbase64[enc >> 2];
113 left = (enc & 3) << 4;
114 mode = 1;
115 break;
116
117 case 1: // we have two bits
118 strRet += pbase64[left | (enc >> 4)];
119 left = (enc & 15) << 2;
120 mode = 2;
121 break;
122
123 case 2: // we have four bits
124 strRet += pbase64[left | (enc >> 6)];
125 strRet += pbase64[enc & 63];
126 mode = 0;
127 break;
128 }
129 }
130
131 if (mode) {
132 strRet += pbase64[left];
133 strRet += '=';
134 if (mode == 1)
135 strRet += '=';
136 }
137
138 return strRet;
139}
140
141string EncodeBase64(const string& str)
142{

Callers 5

signmessageFunction · 0.85
CallRPCFunction · 0.85
GenerateAuthCookieFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 2

reserveMethod · 0.45
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68