]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Cleanup of base64-related header and unit tests
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 3 Feb 2026 09:33:43 +0000 (10:33 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 3 Feb 2026 09:59:06 +0000 (10:59 +0100)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist-crypto.hh
pdns/test-base64_cc.cc

index 74e1c04696cb09ab087ca7854a83dfdda5c6de75..b164c49fed7ba34d9bea2ce16e7e864753ddd517 100644 (file)
@@ -23,7 +23,6 @@
 #include "config.h"
 #include <array>
 #include <string>
-#include <cstdint>
 #include <cstring>
 
 #if defined(HAVE_LIBSODIUM)
@@ -65,7 +64,7 @@ constexpr size_t getEncryptedSize(size_t plainTextSize)
 #if defined(HAVE_LIBSODIUM)
   return plainTextSize + crypto_secretbox_MACBYTES;
 #elif defined(HAVE_LIBCRYPTO)
-  return plainTextSize + 16;
+  return plainTextSize + 16U;
 #else
   return plainTextSize;
 #endif
index d246b0d18e97f6719071bd7e7437c47583ba7480..c2d4ee3722ee839d6cea246a847ba3b75aa62722 100644 (file)
@@ -3,9 +3,7 @@
 #endif
 
 #define BOOST_TEST_NO_MAIN
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+
 #include <boost/test/unit_test.hpp>
 #include <boost/assign/std/map.hpp>
 
@@ -16,21 +14,23 @@ using namespace boost;
 BOOST_AUTO_TEST_SUITE(test_base64_cc)
 
 BOOST_AUTO_TEST_CASE(test_Base64_Roundtrip) {
-  std::string before("Some Random String"), after;
-  std::string encoded = Base64Encode(before);
+  const std::string before("Some Random String");
+  const auto encoded = Base64Encode(before);
+
+  std::string after;
   B64Decode(encoded, after);
   BOOST_CHECK_EQUAL(before, after);
 }
 
-/* for a in $(seq 1 32); 
-   do 
-    plain=$(pwgen -1  -s $a) 
-    echo  \(\"$plain\",\"$(echo -n $plain | openssl enc -base64)\"\) ; 
+/* for a in $(seq 1 32);
+   do
+    plain=$(pwgen -1  -s $a)
+    echo  \(\"$plain\",\"$(echo -n $plain | openssl enc -base64)\"\) ;
    done
 */
 
 BOOST_AUTO_TEST_CASE(test_Base64_Encode) {
-  typedef std::map<std::string, std::string> cases_t;
+  using cases_t = std::map<std::string, std::string>;
   cases_t cases;
   assign::insert(cases)
     ("", "")
@@ -67,10 +67,10 @@ BOOST_AUTO_TEST_CASE(test_Base64_Encode) {
     ("eSHBt7Xx5F7A4HFtabXEzDLD01bnSiG","ZVNIQnQ3WHg1RjdBNEhGdGFiWEV6RExEMDFiblNpRw==")
     ("dq4KydZjmcoQQ45VYBP2EDR8FqKaMul0","ZHE0S3lkWmptY29RUTQ1VllCUDJFRFI4RnFLYU11bDA=");
 
-  for(const cases_t::value_type& val :  cases) {
-    std::string encoded = Base64Encode(val.first), decoded;
+  for (const auto& val : cases) {
+    const auto encoded = Base64Encode(val.first);
     BOOST_CHECK_EQUAL(encoded, val.second);
-    decoded.clear();
+    std::string decoded;
     B64Decode(val.second, decoded);
     BOOST_CHECK_EQUAL(decoded, val.first);
   }