From: Remi Gacogne Date: Mon, 18 Dec 2023 15:25:27 +0000 (+0100) Subject: dnsdist: Delint dnsdist-crypto.cc X-Git-Tag: dnsdist-1.9.0-rc1~24^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=152970b98c714cbfe80f2ee065418748efc89bf3;p=thirdparty%2Fpdns.git dnsdist: Delint dnsdist-crypto.cc --- diff --git a/pdns/dnsdistdist/dnsdist-crypto.cc b/pdns/dnsdistdist/dnsdist-crypto.cc index 88620dcea7..df4beebcb2 100644 --- a/pdns/dnsdistdist/dnsdist-crypto.cc +++ b/pdns/dnsdistdist/dnsdist-crypto.cc @@ -392,21 +392,21 @@ static char B64Decode1(char cInChar) } // switch - return iIndex; + return static_cast(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('A' + input); } - if (uc < 52) { - return 'a' + (uc - 26); + if (input < 52) { + return static_cast('a' + (input - 26)); } - if (uc < 62) { - return '0' + (uc - 52); + if (input < 62) { + return static_cast('0' + (input - 52)); } - if (uc == 62) { + if (input == 62) { return '+'; } return '/'; @@ -420,10 +420,12 @@ int B64Decode(const std::string& strInput, Container& strOutput) { // Set up a decoding buffer long cBuf = 0; - char* pBuf = (char*)&cBuf; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + char* pBuf = reinterpret_cast(&cBuf); // Decoding management... - int iBitGroup = 0, iInNum = 0; + int iBitGroup = 0; + int iInNum = 0; // While there are characters to process... // @@ -435,7 +437,7 @@ int B64Decode(const std::string& strInput, Container& strOutput) // 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(strInput.size()); unsigned char cChar = '\0'; uint8_t pad = 0; while (iInNum < iInSize) { @@ -445,10 +447,12 @@ int B64Decode(const std::string& strInput, Container& strOutput) 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 @@ -458,8 +462,9 @@ int B64Decode(const std::string& strInput, Container& strOutput) } // else // Check for valid decode - if (cChar > 0x7F) + if (cChar > 0x7F) { return -1; + } // Adjust the bits switch (iBitGroup) { @@ -488,17 +493,24 @@ int B64Decode(const std::string& strInput, Container& strOutput) // 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; } @@ -513,35 +525,40 @@ Copyright 2001-2002 Randy Charles Morin 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 {