} // switch
- return iIndex;
+ return static_cast<char>(iIndex);
}
-static inline char B64Encode1(unsigned char uc)
+static inline char B64Encode1(unsigned char input)
{
- if (uc < 26) {
- return 'A' + uc;
+ if (input < 26) {
+ return static_cast<char>('A' + input);
}
- if (uc < 52) {
- return 'a' + (uc - 26);
+ if (input < 52) {
+ return static_cast<char>('a' + (input - 26));
}
- if (uc < 62) {
- return '0' + (uc - 52);
+ if (input < 62) {
+ return static_cast<char>('0' + (input - 52));
}
- if (uc == 62) {
+ if (input == 62) {
return '+';
}
return '/';
{
// Set up a decoding buffer
long cBuf = 0;
- char* pBuf = (char*)&cBuf;
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
+ char* pBuf = reinterpret_cast<char*>(&cBuf);
// Decoding management...
- int iBitGroup = 0, iInNum = 0;
+ int iBitGroup = 0;
+ int iInNum = 0;
// While there are characters to process...
//
// Later, after all 3 bytes have been reconstituted,
// we assign them to the output string, ultimately
// to be returned as the original message.
- int iInSize = strInput.size();
+ int iInSize = static_cast<int>(strInput.size());
unsigned char cChar = '\0';
uint8_t pad = 0;
while (iInNum < iInSize) {
for (iBitGroup = 0; iBitGroup < 4; ++iBitGroup) {
if (iInNum < iInSize) {
// Decode a character
- if (strInput.at(iInNum) == '=')
+ if (strInput.at(iInNum) == '=') {
pad++;
- while (isspace(strInput.at(iInNum)))
+ }
+ while (isspace(strInput.at(iInNum))) {
iInNum++;
+ }
cChar = B64Decode1(strInput.at(iInNum++));
} // if
} // else
// Check for valid decode
- if (cChar > 0x7F)
+ if (cChar > 0x7F) {
return -1;
+ }
// Adjust the bits
switch (iBitGroup) {
// may have been padding, so those padded bytes
// are actually ignored.
#if BYTE_ORDER == BIG_ENDIAN
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
strOutput.push_back(pBuf[sizeof(long) - 3]);
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
strOutput.push_back(pBuf[sizeof(long) - 2]);
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
strOutput.push_back(pBuf[sizeof(long) - 1]);
#else
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
strOutput.push_back(pBuf[2]);
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
strOutput.push_back(pBuf[1]);
+ // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
strOutput.push_back(pBuf[0]);
#endif
} // while
- if (pad)
+ if (pad) {
strOutput.resize(strOutput.size() - pad);
+ }
return 1;
}
The Encode static method takes an array of 8-bit values and returns a base-64 stream.
*/
-std::string Base64Encode(const std::string& vby)
+std::string Base64Encode(const std::string& src)
{
std::string retval;
- if (vby.size() == 0) {
+ if (src.empty()) {
return retval;
- };
- for (unsigned int i = 0; i < vby.size(); i += 3) {
- unsigned char by1 = 0, by2 = 0, by3 = 0;
- by1 = vby[i];
- if (i + 1 < vby.size()) {
- by2 = vby[i + 1];
+ }
+ for (unsigned int i = 0; i < src.size(); i += 3) {
+ unsigned char by1 = 0;
+ unsigned char by2 = 0;
+ unsigned char by3 = 0;
+ by1 = src[i];
+ if (i + 1 < src.size()) {
+ by2 = src[i + 1];
};
- if (i + 2 < vby.size()) {
- by3 = vby[i + 2];
+ if (i + 2 < src.size()) {
+ by3 = src[i + 2];
}
- unsigned char by4 = 0, by5 = 0, by6 = 0, by7 = 0;
+ unsigned char by4 = 0;
+ unsigned char by5 = 0;
+ unsigned char by6 = 0;
+ unsigned char by7 = 0;
by4 = by1 >> 2;
by5 = ((by1 & 0x3) << 4) | (by2 >> 4);
by6 = ((by2 & 0xf) << 2) | (by3 >> 6);
by7 = by3 & 0x3f;
retval += B64Encode1(by4);
retval += B64Encode1(by5);
- if (i + 1 < vby.size()) {
+ if (i + 1 < src.size()) {
retval += B64Encode1(by6);
}
else {
retval += "=";
};
- if (i + 2 < vby.size()) {
+ if (i + 2 < src.size()) {
retval += B64Encode1(by7);
}
else {