Repository: randombit/botan
Pull request #3289 (2023-02-15 21:08:30)

More clang-tidy warning fixes


Patch:
diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp
index d3a26a769..3e61dcbe3 100644
--- a/src/cli/cli.cpp
+++ b/src/cli/cli.cpp
@@ -31,7 +31,7 @@ Command::Command(const std::string& cmd_spec) : m_spec(cmd_spec)
    //m_args.reset(new Argument_Parser(m_spec));
    }
 
-Command::~Command() { /* for unique_ptr */ }
+Command::~Command() = default;
 
 std::string Command::cmd_name() const
    {
@@ -168,7 +168,7 @@ std::vector<std::string> Command::get_arg_list(const std::string& what) const
 
 std::ostream& Command::output()
    {
-   if(m_output_stream.get())
+   if(m_output_stream)
       {
       return *m_output_stream;
       }
@@ -177,7 +177,7 @@ std::ostream& Command::output()
 
 std::ostream& Command::error_output()
    {
-   if(m_error_output_stream.get())
+   if(m_error_output_stream)
       {
       return *m_error_output_stream;
       }
@@ -250,7 +250,7 @@ Botan::RandomNumberGenerator& Command::rng()
       m_rng = cli_make_rng(get_arg("rng-type"), get_arg("drbg-seed"));
       }
 
-   return *m_rng.get();
+   return *m_rng;
    }
 
 std::string Command::get_passphrase_arg(const std::string& prompt, const std::string& opt_name)
diff --git a/src/cli/sandbox.cpp b/src/cli/sandbox.cpp
index eeabdc0ef..1c1ab21c3 100644
--- a/src/cli/sandbox.cpp
+++ b/src/cli/sandbox.cpp
@@ -124,7 +124,6 @@ bool Sandbox::init()
 #endif
    }
 
-Sandbox::~Sandbox()
-   {
-   }
+Sandbox::~Sandbox() = default;
+
 }
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index 096bb5e9c..d6ee7b0c5 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -188,7 +188,7 @@ class JSON_Output final
 class Summary final
    {
    public:
-      Summary() {}
+      Summary() = default;
 
       void add(const Timer& t)
          {
diff --git a/src/lib/misc/roughtime/roughtime.cpp b/src/lib/misc/roughtime/roughtime.cpp
index 5fc7a2d57..b118c46f0 100644
--- a/src/lib/misc/roughtime/roughtime.cpp
+++ b/src/lib/misc/roughtime/roughtime.cpp
@@ -119,7 +119,7 @@ bool verify_signature(const std::array<uint8_t, 32>& pk, const std::vector<uint8
 
 std::array<uint8_t, 64> hashLeaf(const std::array<uint8_t, 64>& leaf)
    {
-   std::array<uint8_t, 64> ret;
+   std::array<uint8_t, 64> ret{};
    std::unique_ptr<HashFunction> hash(HashFunction::create_or_throw("SHA-512"));
    hash->update(0);
    hash->update(leaf.data(), leaf.size());
@@ -194,8 +194,8 @@ Response Response::from_bits(const std::vector<uint8_t>& response,
    const auto indx = get<uint32_t>(response_v, "INDX");
    const auto path = get_v(response_v, "PATH");
    const auto srep_root = get<std::array<uint8_t, 64>>(srep_v, "ROOT");
-   const auto size = path.size();
-   const auto levels = size/64;
+   const size_t size = path.size();
+   const size_t levels = size / 64;
 
    if(size % 64)
       { throw Roughtime_Error("Merkle tree path size must be multiple of 64 bytes"); }
@@ -204,7 +204,7 @@ Response Response::from_bits(const std::vector<uint8_t>& response,
 
    auto hash = hashLeaf(nonce.get_nonce());
    auto index = indx;
-   auto level = 0u;
+   size_t level = 0;
    while(level < levels)
       {
       hashNode(hash, typecast_copy<std::array<uint8_t, 64>>(path.data() + level*64), index&1);
@@ -238,7 +238,7 @@ bool Response::validate(const Ed25519_PublicKey& pk) const
 Nonce nonce_from_blind(const std::vector<uint8_t>& previous_response,
                        const Nonce& blind)
    {
-   std::array<uint8_t, 64> ret;
+   std::array<uint8_t, 64> ret{};
    const auto blind_arr = blind.get_nonce();
    std::unique_ptr<HashFunction> hash(HashFunction::create_or_throw("SHA-512"));
    hash->update(previous_response);
diff --git a/src/lib/prov/pkcs11/p11_rsa.cpp b/src/lib/prov/pkcs11/p11_rsa.cpp
index e7f7036e4..83949ec55 100644
--- a/src/lib/prov/pkcs11/p11_rsa.cpp
+++ b/src/lib/prov/pkcs11/p11_rsa.cpp
@@ -63,14 +63,13 @@ PKCS11_RSA_PrivateKey::PKCS11_RSA_PrivateKey(Session& session, ObjectHandle hand
 PKCS11_RSA_PrivateKey::PKCS11_RSA_PrivateKey(Session& session, const RSA_PrivateKeyImportProperties& priv_key_props)
    : Object(session, priv_key_props),
      RSA_PublicKey(priv_key_props.modulus(),
-                   BigInt::decode(get_attribute_value(AttributeType::PublicExponent))),
-     m_use_software_padding(false)
+                   BigInt::decode(get_attribute_value(AttributeType::PublicExponent)))
    {
    }
 
 PKCS11_RSA_PrivateKey::PKCS11_RSA_PrivateKey(Session& session, uint32_t bits,
                                              const RSA_PrivateKeyGenerationProperties& priv_key_props)
-   : Object(session), RSA_PublicKey(), m_use_software_padding(false)
+   : Object(session), RSA_PublicKey()
    {
    RSA_PublicKeyGenerationProperties pub_key_props(bits);
    pub_key_props.set_encrypt(true);
diff --git a/src/lib/prov/pkcs11/p11_rsa.h b/src/lib/prov/pkcs11/p11_rsa.h
index ceb78ed2c..492e94814 100644
--- a/src/lib/prov/pkcs11/p11_rsa.h
+++ b/src/lib/prov/pkcs11/p11_rsa.h
@@ -223,7 +223,7 @@ class BOTAN_PUBLIC_API(2,0) PKCS11_RSA_PrivateKey final :
                              const std::string& provider) const override;
 
    private:
-      bool m_use_software_padding;
+      bool m_use_software_padding = false;
    };
 
 using PKCS11_RSA_KeyPair = std::pair<PKCS11_RSA_PublicKey, PKCS11_RSA_PrivateKey>;
diff --git a/src/lib/prov/pkcs11/p11_session.cpp b/src/lib/prov/pkcs11/p11_session.cpp
index c2aea6ac7..50ad48c83 100644
--- a/src/lib/prov/pkcs11/p11_session.cpp
+++ b/src/lib/prov/pkcs11/p11_session.cpp
@@ -81,11 +81,13 @@ SessionInfo Session::get_info() const
    return info;
    }
 
+// NOLINTNEXTLINE(readability-make-member-function-const)
 void Session::set_pin(const secure_string& old_pin, const secure_string& new_pin)
    {
    module()->C_SetPIN(m_handle, old_pin, new_pin);
    }
 
+// NOLINTNEXTLINE(readability-make-member-function-const)
 void Session::init_pin(const secure_string& new_pin)
    {
    module()->C_InitPIN(m_handle, new_pin);
diff --git a/src/lib/pubkey/dilithium/dilithium_common/dilithium.cpp b/src/lib/pubkey/dilithium/dilithium_common/dilithium.cpp
index dbd88ea7d..a420b8242 100644
--- a/src/lib/pubkey/dilithium/dilithium_common/dilithium.cpp
+++ b/src/lib/pubkey/dilithium/dilithium_common/dilithium.cpp
@@ -188,7 +188,7 @@ class Dilithium_PublicKeyInternal : public ASN1_Object
       Dilithium_PublicKeyInternal& operator=(const Dilithium_PublicKeyInternal& other) = delete;
       Dilithium_PublicKeyInternal& operator=(Dilithium_PublicKeyInternal&& other) = delete;
 
-      ~Dilithium_PublicKeyInternal() = default;
+      ~Dilithium_PublicKeyInternal() override = default;
 
       void encode_into(DER_Encoder& to) const override
          {
@@ -694,7 +694,7 @@ Dilithium_PrivateKey::Dilithium_PrivateKey(RandomNumberGenerator& rng, Dilithium
    m_public = std::make_shared<Dilithium_PublicKeyInternal>(mode, rho, std::move(t1));
 
    /* Compute H(rho, t1) == H(pk) and write secret key */
-   const auto tr = mode.H(m_public->raw_pk(), DilithiumModeConstants::SEEDBYTES);
+   auto tr = mode.H(m_public->raw_pk(), DilithiumModeConstants::SEEDBYTES);
 
    m_private = std::make_shared<Dilithium_PrivateKeyInternal>(std::move(mode), std::move(rho), std::move(tr), std::move(key),
                                                               std::move(s1), std::move(s2), std::move(t0));
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp
index a0f5b519c..c73119143 100644
--- a/src/lib/pubkey/ec_group/ec_group.cpp
+++ b/src/lib/pubkey/ec_group/ec_group.cpp
@@ -154,7 +154,7 @@ class EC_Group_Data final
 class EC_Group_Data_Map final
    {
    public:
-      EC_Group_Data_Map() {}
+      EC_Group_Data_Map() = default;
 
       size_t clear()
          {
@@ -419,9 +419,7 @@ std::shared_ptr<EC_Group_Data> EC_Group::BER_decode_EC_group(const uint8_t bits[
       }
    }
 
-EC_Group::EC_Group()
-   {
-   }
+EC_Group::EC_Group() = default;
 
 EC_Group::~EC_Group() = default;
 
diff --git a/src/lib/pubkey/kyber/kyber_common/kyber.cpp b/src/lib/pubkey/kyber/kyber_common/kyber.cpp
index 67d85f7a1..47571db69 100644
--- a/src/lib/pubkey/kyber/kyber_common/kyber.cpp
+++ b/src/lib/pubkey/kyber/kyber_common/kyber.cpp
@@ -823,8 +823,8 @@ class Ciphertext
 
    public:
       Ciphertext() = delete;
-      Ciphertext(PolynomialVector b_, Polynomial v_, KyberConstants mode)
-         : m_mode(std::move(mode)), b(std::move(b_)), v(std::move(v_))
+      Ciphertext(PolynomialVector b_, const Polynomial& v_, KyberConstants mode)
+         : m_mode(std::move(mode)), b(std::move(b_)), v(v_)
          {
          }
 
@@ -1175,7 +1175,7 @@ class Kyber_KEM_Cryptor
          bp.reduce();
          v.reduce();
 
-         return Ciphertext(std::move(bp), std::move(v), m_mode).to_bytes();
+         return Ciphertext(std::move(bp), v, m_mode).to_bytes();
          }
    };
 
diff --git a/src/lib/pubkey/mce/polyn_gf2m.cpp b/src/lib/pubkey/mce/polyn_gf2m.cpp
index 8ef17fca5..659d1d695 100644
--- a/src/lib/pubkey/mce/polyn_gf2m.cpp
+++ b/src/lib/pubkey/mce/polyn_gf2m.cpp
@@ -88,11 +88,7 @@ gf2m random_code_element(uint16_t code_length, RandomNumberGenerator& rng)
    return result;
    }
 
-polyn_gf2m::polyn_gf2m(polyn_gf2m const& other)
-   :m_deg(other.m_deg),
-    m_coeff(other.m_coeff),
-    m_sp_field(other.m_sp_field)
-   { }
+polyn_gf2m::polyn_gf2m(const polyn_gf2m& other) = default;
 
 polyn_gf2m::polyn_gf2m(int d, const std::shared_ptr<GF2m_Field>& sp_field)
    :m_deg(-1),
diff --git a/src/lib/pubkey/rfc6979/rfc6979.cpp b/src/lib/pubkey/rfc6979/rfc6979.cpp
index 5270a5aa8..063b468fb 100644
--- a/src/lib/pubkey/rfc6979/rfc6979.cpp
+++ b/src/lib/pubkey/rfc6979/rfc6979.cpp
@@ -24,10 +24,7 @@ RFC6979_Nonce_Generator::RFC6979_Nonce_Generator(const std::string& hash,
    BigInt::encode_1363(m_rng_in.data(), m_rlen, x);
    }
 
-RFC6979_Nonce_Generator::~RFC6979_Nonce_Generator()
-   {
-   // for ~unique_ptr
-   }
+RFC6979_Nonce_Generator::~RFC6979_Nonce_Generator() = default;
 
 const BigInt& RFC6979_Nonce_Generator::nonce_for(const BigInt& m)
    {
diff --git a/src/lib/pubkey/xmss/xmss_wots_parameters.cpp b/src/lib/pubkey/xmss/xmss_wots_parameters.cpp
index e8564e8ea..2e46253fc 100644
--- a/src/lib/pubkey/xmss/xmss_wots_parameters.cpp
+++ b/src/lib/pubkey/xmss/xmss_wots_parameters.cpp
@@ -116,7 +116,7 @@ XMSS_WOTS_Parameters::base_w(size_t value) const
    {
    value <<= (8 - ((m_len_2 * m_lg_w) % 8));
    size_t len_2_bytes = static_cast<size_t>(
-                           std::ceil(static_cast<float>(m_len_2 * m_lg_w) / 8.f));
+                           std::ceil(static_cast<float>(m_len_2 * m_lg_w) / 8.0));
    secure_vector<uint8_t> result;
    XMSS_Tools::concat(result, value, len_2_bytes);
    return base_w(result, m_len_2);
diff --git a/src/lib/tls/msg_cert_verify.cpp b/src/lib/tls/msg_cert_verify.cpp
index 908ceadb7..51e8a9bb3 100644
--- a/src/lib/tls/msg_cert_verify.cpp
+++ b/src/lib/tls/msg_cert_verify.cpp
@@ -91,7 +91,7 @@ bool Certificate_Verify_12::verify(const X509_Certificate& cert,
    policy.check_peer_key_acceptable(*key);
 
    std::pair<std::string, Signature_Format> format =
-      state.parse_sig_format(*key.get(), m_scheme, state.client_hello()->signature_schemes(), true, policy);
+      state.parse_sig_format(*key, m_scheme, state.client_hello()->signature_schemes(), true, policy);
 
    const bool signature_valid =
       state.callbacks().tls_verify_message(*key, format.first, format.second,
diff --git a/src/lib/tls/tls12/msg_client_kex.cpp b/src/lib/tls/tls12/msg_client_kex.cpp
index 425d76f4f..f6b803955 100644
--- a/src/lib/tls/tls12/msg_client_kex.cpp
+++ b/src/lib/tls/tls12/msg_client_kex.cpp
@@ -36,7 +36,7 @@ Client_Key_Exchange::Client_Key_Exchange(Handshake_IO& io,
 
    if(kex_algo == Kex_Algo::PSK)
       {
-      std::string identity_hint = "";
+      std::string identity_hint;
 
       if(state.server_kex())
          {
diff --git a/src/lib/tls/tls12/tls_channel_impl_12.cpp b/src/lib/tls/tls12/tls_channel_impl_12.cpp
index 917e6f30d..4af128dff 100644
--- a/src/lib/tls/tls12/tls_channel_impl_12.cpp
+++ b/src/lib/tls/tls12/tls_channel_impl_12.cpp
@@ -66,10 +66,7 @@ void Channel_Impl_12::reset_active_association_state()
       m_sequence_numbers->reset();
    }
 
-Channel_Impl_12::~Channel_Impl_12()
-   {
-   // So unique_ptr destructors run correctly
-   }
+Channel_Impl_12::~Channel_Impl_12() = default;
 
 Connection_Sequence_Numbers& Channel_Impl_12::sequence_numbers() const
    {
@@ -152,7 +149,7 @@ Handshake_State& Channel_Impl_12::create_handshake_state(Protocol_Version versio
    if(auto active = active_state())
       m_pending_state->set_version(active->version());
 
-   return *m_pending_state.get();
+   return *m_pending_state;
    }
 
 bool Channel_Impl_12::timeout_check()
diff --git a/src/lib/tls/tls13/msg_certificate_13.cpp b/src/lib/tls/tls13/msg_certificate_13.cpp
index e8457444b..683c38869 100644
--- a/src/lib/tls/tls13/msg_certificate_13.cpp
+++ b/src/lib/tls/tls13/msg_certificate_13.cpp
@@ -165,7 +165,7 @@ void Certificate_13::setup_entries(std::vector<X509_Certificate> cert_chain,
       entry.certificate = cert_chain[i];
       if(!ocsp_responses[i].empty())
          {
-         entry.extensions.add(new Certificate_Status_Request(std::move(ocsp_responses[i])));
+         entry.extensions.add(new Certificate_Status_Request(ocsp_responses[i]));
          }
       }
    }
diff --git a/src/lib/tls/tls13/tls_extensions_psk.cpp b/src/lib/tls/tls13/tls_extensions_psk.cpp
index 5816c3965..a987c32c7 100644
--- a/src/lib/tls/tls13/tls_extensions_psk.cpp
+++ b/src/lib/tls/tls13/tls_extensions_psk.cpp
@@ -55,7 +55,7 @@ uint32_t obfuscate_ticket_age(std::chrono::milliseconds ticket_age, uint32_t tic
 class PSK::PSK_Internal
    {
    public:
-      PSK_Internal(Server_PSK srv_psk) : psk(std::move(srv_psk)) {}
+      PSK_Internal(Server_PSK srv_psk) : psk(srv_psk) {}
       PSK_Internal(std::vector<Client_PSK> clt_psks) : psk(std::move(clt_psks)) {}
 
       std::variant<std::vector<Client_PSK>, Server_PSK> psk;
diff --git a/src/lib/tls/tls13/tls_record_layer_13.cpp b/src/lib/tls/tls13/tls_record_layer_13.cpp
index d3d0f3f4a..d379207d4 100644
--- a/src/lib/tls/tls13/tls_record_layer_13.cpp
+++ b/src/lib/tls/tls13/tls_record_layer_13.cpp
@@ -171,7 +171,7 @@ void Record_Layer::copy_data(const std::vector<uint8_t>& data_from_peer)
 
 std::vector<uint8_t> Record_Layer::prepare_records(const Record_Type type,
       const std::vector<uint8_t>& data,
-      Cipher_State* cipher_state)
+      Cipher_State* cipher_state) const
    {
    // RFC 8446 5.
    //    Note that [change_cipher_spec records] may appear at a point at the
diff --git a/src/lib/tls/tls13/tls_record_layer_13.h b/src/lib/tls/tls13/tls_record_layer_13.h
index e4ffa6144..d77424a31 100644
--- a/src/lib/tls/tls13/tls_record_layer_13.h
+++ b/src/lib/tls/tls13/tls_record_layer_13.h
@@ -76,7 +76,7 @@ class BOTAN_TEST_API Record_Layer
 
       std::vector<uint8_t> prepare_records(const Record_Type type,
                                            const std::vector<uint8_t>& data,
-                                           Cipher_State* cipher_state=nullptr);
+                                           Cipher_State* cipher_state=nullptr) const;
 
       /**
        * Clears any data currently stored in the read buffer. This is typically
diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp
index be1f83df4..910e14fc1 100644
--- a/src/lib/tls/tls_extensions.cpp
+++ b/src/lib/tls/tls_extensions.cpp
@@ -800,7 +800,7 @@ Cookie::Cookie(TLS_Data_Reader& reader,
       throw Decoding_Error("Not enough bytes in the buffer to decode Cookie");
       }
 
-   for (auto i = 0u; i < len; ++i)
+   for(size_t i = 0; i < len; ++i)
       {
       m_cookie.push_back(reader.get_byte());
       }
diff --git a/src/lib/utils/mem_pool/mem_pool.cpp b/src/lib/utils/mem_pool/mem_pool.cpp
index e3185b1e5..dba33b2e0 100644
--- a/src/lib/utils/mem_pool/mem_pool.cpp
+++ b/src/lib/utils/mem_pool/mem_pool.cpp
@@ -318,7 +318,7 @@ Memory_Pool::Memory_Pool(const std::vector<void*>& pages, size_t page_size) :
    m_max_page_ptr += page_size;
    }
 
-Memory_Pool::~Memory_Pool()
+Memory_Pool::~Memory_Pool() // NOLINT(*-use-equals-default)
    {
 #if defined(BOTAN_MEM_POOL_USE_MMU_PROTECTIONS)
    for(size_t i = 0; i != m_free_pages.size(); ++i)
diff --git a/src/lib/utils/parsing.cpp b/src/lib/utils/parsing.cpp
index 51b2334e2..a8115cab2 100644
--- a/src/lib/utils/parsing.cpp
+++ b/src/lib/utils/parsing.cpp
@@ -13,6 +13,7 @@
 #include <algorithm>
 #include <cctype>
 #include <limits>
+#include <sstream>
 
 namespace Botan {
 
@@ -138,16 +139,16 @@ std::vector<std::string> split_on(const std::string& str, char delim)
 */
 std::string string_join(const std::vector<std::string>& strs, char delim)
    {
-   std::string out = "";
+   std::ostringstream out;
 
    for(size_t i = 0; i != strs.size(); ++i)
       {
       if(i != 0)
-         out += delim;
-      out += strs[i];
+         out << delim;
+      out << strs[i];
       }
 
-   return out;
+   return out.str();
    }
 
 /*
diff --git a/src/lib/x509/certstor.cpp b/src/lib/x509/certstor.cpp
index 4c97a672e..b0053afa0 100644
--- a/src/lib/x509/certstor.cpp
+++ b/src/lib/x509/certstor.cpp
@@ -14,7 +14,7 @@
 
 namespace Botan {
 
-Certificate_Store::~Certificate_Store() {}
+Certificate_Store::~Certificate_Store() = default;
 
 std::optional<X509_Certificate>
 Certificate_Store::find_cert(const X509_DN& subject_dn, const std::vector<uint8_t>& key_id) const
diff --git a/src/lib/x509/crl_ent.cpp b/src/lib/x509/crl_ent.cpp
index 296fcd729..0201fce32 100644
--- a/src/lib/x509/crl_ent.cpp
+++ b/src/lib/x509/crl_ent.cpp
@@ -113,7 +113,7 @@ const CRL_Entry_Data& CRL_Entry::data() const
       throw Invalid_State("CRL_Entry_Data uninitialized");
       }
 
-   return *m_data.get();
+   return *m_data;
    }
 
 const std::vector<uint8_t>& CRL_Entry::serial_number() const
diff --git a/src/lib/x509/pkcs10.cpp b/src/lib/x509/pkcs10.cpp
index 1043b320b..814816f94 100644
--- a/src/lib/x509/pkcs10.cpp
+++ b/src/lib/x509/pkcs10.cpp
@@ -194,7 +194,7 @@ const PKCS10_Data& PKCS10_Request::data() const
    {
    if(m_data == nullptr)
       throw Decoding_Error("PKCS10_Request decoding failed");
-   return *m_data.get();
+   return *m_data;
    }
 
 /*
diff --git a/src/lib/x509/x509_ca.cpp b/src/lib/x509/x509_ca.cpp
index adb3ae37f..cac7bb6fb 100644
--- a/src/lib/x509/x509_ca.cpp
+++ b/src/lib/x509/x509_ca.cpp
@@ -32,13 +32,7 @@ X509_CA::X509_CA(const X509_Certificate& cert,
    m_signer = X509_Object::choose_sig_format(m_ca_sig_algo, key, rng, hash_fn, padding_method);
    }
 
-/*
-* X509_CA Destructor
-*/
-X509_CA::~X509_CA()
-   {
-   /* for unique_ptr */
-   }
+X509_CA::~X509_CA() = default;
 
 namespace {
 
diff --git a/src/lib/x509/x509_crl.cpp b/src/lib/x509/x509_crl.cpp
index 7d3c440fe..dbebb758d 100644
--- a/src/lib/x509/x509_crl.cpp
+++ b/src/lib/x509/x509_crl.cpp
@@ -201,7 +201,7 @@ const CRL_Data& X509_CRL::data() const
       {
       throw Invalid_State("X509_CRL uninitialized");
       }
-   return *m_data.get();
+   return *m_data;
    }
 
 const Extensions& X509_CRL::extensions() const
diff --git a/src/lib/x509/x509cert.cpp b/src/lib/x509/x509cert.cpp
index 417aaaac2..20988232b 100644
--- a/src/lib/x509/x509cert.cpp
+++ b/src/lib/x509/x509cert.cpp
@@ -371,7 +371,7 @@ const X509_Certificate_Data& X509_Certificate::data() const
       {
       throw Invalid_State("X509_Certificate uninitialized");
       }
-   return *m_data.get();
+   return *m_data;
    }
 
 uint32_t X509_Certificate::x509_version() const
diff --git a/src/scripts/dev_tools/run_clang_tidy.py b/src/scripts/dev_tools/run_clang_tidy.py
index 38636fd55..11a00057f 100755
--- a/src/scripts/dev_tools/run_clang_tidy.py
+++ b/src/scripts/dev_tools/run_clang_tidy.py
@@ -1,5 +1,11 @@
 #!/usr/bin/env python3
 
+"""
+(C) 2022,2023 Jack Lloyd
+
+Botan is released under the Simplified BSD License (see license.txt)
+"""
+
 import subprocess
 import sys
 import json
@@ -7,70 +13,64 @@ import optparse
 import os
 import multiprocessing
 import re
+import time
 from multiprocessing.pool import ThreadPool
 
 enabled_checks = [
     'bugprone-*',
     'cert-*',
     'clang-analyzer-*',
+    'cppcoreguidelines-*',
+    'hicpp-*',
+    'modernize-*',
     'performance-*',
     'portability-*',
-
-    'modernize-concat-nested-namespaces',
-    'modernize-make-unique',
-    'modernize-make-shared',
-
-    'readability-container-size-empty',
-    'readability-static-definition-in-anonymous-namespace',
-    'readability-convert-member-functions-to-static',
-
-    'hicpp-special-member-functions',
-
-#    'cppcoreguidelines-*',
-#    'hicpp-*',
-#    'modernize-*',
-#    'readability-*',
+    'readability-*',
 ]
 
 # these might be worth being clean for
 disabled_needs_work = [
     '*-braces-around-statements', # should fix (need clang-format)
+    '*-named-parameter',
+    '*-member-init', # seems bad
     'bugprone-easily-swappable-parameters',
     'bugprone-implicit-widening-of-multiplication-result',
+    'bugprone-lambda-function-name', # should be an easy fix
     'bugprone-macro-parentheses', # should be fixed (using inline/constexpr)
     'bugprone-narrowing-conversions', # should be fixed
     'bugprone-unchecked-optional-access', # clang-tidy seems buggy (many false positives)
-    'bugprone-lambda-function-name', # should be an easy fix
     'cppcoreguidelines-init-variables',
-    'cppcoreguidelines-narrowing-conversions', # lot of these
     'cppcoreguidelines-macro-usage',
+    'cppcoreguidelines-narrowing-conversions', # lot of these
     'cppcoreguidelines-owning-memory',
     'cppcoreguidelines-prefer-member-initializer',
     'cppcoreguidelines-pro-bounds-pointer-arithmetic',
     'cppcoreguidelines-pro-type-union-access', # only in sha1_sse2
     'cppcoreguidelines-slicing', # private->public key slicing
-    'hicpp-signed-bitwise', # djb shit
     'hicpp-explicit-conversions',
+    'hicpp-signed-bitwise', # djb shit
+    'hicpp-move-const-arg',
+    'modernize-avoid-bind', # used a lot in pkcs11
     'modernize-pass-by-value',
     'modernize-use-nodiscard',
-    'modernize-avoid-bind', # used a lot in pkcs11
     'modernize-use-trailing-return-type',
     'performance-inefficient-string-concatenation',
     'performance-inefficient-vector-operation',
-    'performance-no-int-to-ptr',
-    'performance-unnecessary-copy-initialization',
     'performance-move-const-arg',
     'performance-no-automatic-move',
+    'performance-no-int-to-ptr',
+    'performance-unnecessary-copy-initialization',
+    'readability-container-contains',
     'readability-convert-member-functions-to-static',
     'readability-implicit-bool-conversion', # maybe fix this
     'readability-inconsistent-declaration-parameter-name', # should fix this
     'readability-isolate-declaration',
-    'readability-simplify-boolean-expr', # sometimes ok
     'readability-qualified-auto',
+    'readability-redundant-access-specifiers',
     'readability-redundant-member-init',
     'readability-redundant-string-cstr',
-    'readability-redundant-access-specifiers',
-    'readability-container-contains',
+    'readability-simplify-boolean-expr', # sometimes ok
+    'readability-static-accessed-through-instance',
 ]
 
 # these we are not interested in ever being clang-tidy clean for
@@ -83,17 +83,17 @@ disabled_not_interested = [
     '*-no-array-decay',
     '*-use-auto', # not universally a good idea
     '*-use-emplace', # often less clear
-    '-*deprecated-headers', # wrong for system headers like stdlib.h
+    '*-deprecated-headers', # wrong for system headers like stdlib.h
     'bugprone-argument-comment',
     'bugprone-branch-clone', # doesn't interact well with feature macros
     'cert-err58-cpp',
-    'cppcoreguidelines-no-malloc',
-    'cppcoreguidelines-pro-bounds-constant-array-index',
     'cppcoreguidelines-avoid-non-const-global-variables',
+    'cppcoreguidelines-no-malloc',
     'cppcoreguidelines-non-private-member-variables-in-classes', # pk split keys
+    'cppcoreguidelines-pro-bounds-constant-array-index',
+    'cppcoreguidelines-pro-type-const-cast', # see above
     'cppcoreguidelines-pro-type-cstyle-cast', # system headers
     'cppcoreguidelines-pro-type-reinterpret-cast', # not possible thanks though
-    'cppcoreguidelines-pro-type-const-cast', # see above
     'cppcoreguidelines-pro-type-vararg', # idiocy
     'hicpp-no-assembler',
     'hicpp-no-malloc',
@@ -101,15 +101,15 @@ disabled_not_interested = [
     'modernize-loop-convert', # sometimes very ugly
     'modernize-raw-string-literal',
     'modernize-return-braced-init-list', # thanks I hate it
-    'modernize-use-using', # fine not great
     'modernize-use-default-member-init',
+    'modernize-use-using', # fine not great
     'portability-simd-intrinsics',
+    'readability-container-data-pointer',
     'readability-function-cognitive-complexity',
-    'readability-use-anyofallof', # not more readable
     'readability-identifier-length', # lol, lmao
-    'readability-container-data-pointer',
-    'readability-suspicious-call-argument',
     'readability-non-const-parameter',
+    'readability-suspicious-call-argument',
+    'readability-use-anyofallof', # not more readable
 ]
 
 disabled_checks = disabled_needs_work + disabled_not_interested
@@ -122,6 +122,18 @@ def load_compile_commands(build_dir):
     compile_commands = open(compile_commands_file).read()
     return (compile_commands_file, json.loads(compile_commands))
 
+def run_command(cmdline):
+    proc = subprocess.Popen(cmdline,
+                            stdout=subprocess.PIPE,
+                            stderr=subprocess.PIPE)
+
+    (stdout, stderr) = proc.communicate()
+
+    stdout = stdout.decode('utf8')
+    # stderr discarded
+
+    return stdout
+
 def run_clang_tidy(compile_commands_file,
                    check_config,
                    source_file,
@@ -137,14 +149,7 @@ def run_clang_tidy(compile_commands_file,
 
     cmdline.append(source_file)
 
-    clang_tidy = subprocess.Popen(cmdline,
-                                  stdout=subprocess.PIPE,
-                                  stderr=subprocess.PIPE)
-
-    (stdout, stderr) = clang_tidy.communicate()
-
-    stdout = stdout.decode('utf8')
-    # stderr discarded
+    stdout = run_command(cmdline)
 
     if options.verbose:
         print(source_file)
@@ -171,6 +176,7 @@ def main(args = None):
     parser.add_option('--verbose', action='store_true', default=False)
     parser.add_option('--fixit', action='store_true', default=False)
     parser.add_option('--build-dir', default='build')
+    parser.add_option('--list-checks', action='store_true', default=False)
 
     (options, args) = parser.parse_args(args)
 
@@ -191,8 +197,15 @@ def main(args = None):
 
     check_config = create_check_option(enabled_checks, disabled_checks)
 
+    if options.list_checks:
+        print(run_command(['clang-tidy', '-list-checks', '-checks', check_config]))
+        return 0
+
     pool = ThreadPool(jobs)
 
+    start_time = time.time()
+    files_checked = 0
+
     results = []
     for info in compile_commands:
         file = info['file']
@@ -200,6 +213,7 @@ def main(args = None):
         if not file_matches(file, args[1:]):
             continue
 
+        files_checked += 1
         results.append(pool.apply_async(
             run_clang_tidy,
             (compile_commands_file,
@@ -210,6 +224,10 @@ def main(args = None):
     for result in results:
         result.get()
 
+    time_consumed = time.time() - start_time
+
+    print("Checked %d files in %d seconds" % (files_checked, time_consumed))
+
     return 0
 
 if __name__ == '__main__':


Test patch:
diff --git a/src/tests/test_kyber.cpp b/src/tests/test_kyber.cpp
index 6c5b45925..10572fd20 100644
--- a/src/tests/test_kyber.cpp
+++ b/src/tests/test_kyber.cpp
@@ -273,7 +273,7 @@ class Kyber_Encoding_Test : public Text_Based_Test
          }
 
    public:
-      bool skip_this_test(const std::string &algo_name, const VarMap &) override
+      bool skip_this_test(const std::string &algo_name, const VarMap& /*vars*/) override
          {
          const auto mode = name_to_mode(algo_name);
 #if defined(BOTAN_HAS_KYBER)
diff --git a/src/tests/test_pkcs11_high_level.cpp b/src/tests/test_pkcs11_high_level.cpp
index be82df146..017db90d2 100644
--- a/src/tests/test_pkcs11_high_level.cpp
+++ b/src/tests/test_pkcs11_high_level.cpp
@@ -10,7 +10,6 @@
 #include "tests.h"
 #include "test_pkcs11.h"
 
-#include <memory>
 #include <string>
 #include <vector>
 #include <memory>
diff --git a/src/tests/test_pkcs11_low_level.cpp b/src/tests/test_pkcs11_low_level.cpp
index b38397ca4..de134456f 100644
--- a/src/tests/test_pkcs11_low_level.cpp
+++ b/src/tests/test_pkcs11_low_level.cpp
@@ -53,12 +53,12 @@ class RAII_LowLevel
                {
                if(m_is_logged_in)
                   {
-                  m_low_level.get()->C_Logout(m_session_handle, nullptr);
+                  m_low_level->C_Logout(m_session_handle, nullptr);
                   }
 
-               m_low_level.get()->C_CloseSession(m_session_handle, nullptr);
+               m_low_level->C_CloseSession(m_session_handle, nullptr);
                }
-            m_low_level.get()->C_Finalize(nullptr, nullptr);
+            m_low_level->C_Finalize(nullptr, nullptr);
             }
          catch(...)
             {
@@ -74,7 +74,7 @@ class RAII_LowLevel
       std::vector<SlotId> get_slots(bool token_present) const
          {
          std::vector<SlotId> slots;
-         m_low_level.get()->C_GetSlotList(token_present, slots);
+         m_low_level->C_GetSlotList(token_present, slots);
 
          if(slots.empty())
             {
@@ -87,7 +87,7 @@ class RAII_LowLevel
       inline SessionHandle open_session(Flags session_flags)
          {
          std::vector<SlotId> slots = get_slots(true);
-         m_low_level.get()->C_OpenSession(slots.at(0), session_flags, nullptr, nullptr, &m_session_handle);
+         m_low_level->C_OpenSession(slots.at(0), session_flags, nullptr, nullptr, &m_session_handle);
          m_is_session_open = true;
          return m_session_handle;
          }
@@ -116,7 +116,7 @@ class RAII_LowLevel
             throw Test_Error("no open session");
             }
 
-         m_low_level.get()->C_CloseSession(m_session_handle);
+         m_low_level->C_CloseSession(m_session_handle);
          m_is_session_open = false;
          }
 
@@ -132,7 +132,7 @@ class RAII_LowLevel
             throw Test_Error("Already logged in");
             }
 
-         m_low_level.get()->C_Login(m_session_handle, user_type, pin);
+         m_low_level->C_Login(m_session_handle, user_type, pin);
          m_is_logged_in = true;
          }
 
@@ -143,7 +143,7 @@ class RAII_LowLevel
             throw Test_Error("Not logged in");
             }
 
-         m_low_level.get()->C_Logout(m_session_handle);
+         m_low_level->C_Logout(m_session_handle);
          m_is_logged_in = false;
          }
 
diff --git a/src/tests/test_pubkey.cpp b/src/tests/test_pubkey.cpp
index b419faaf3..33656d88e 100644
--- a/src/tests/test_pubkey.cpp
+++ b/src/tests/test_pubkey.cpp
@@ -624,7 +624,7 @@ void test_pbe_roundtrip(Test::Result& result,
       std::unique_ptr<Botan::Private_Key> loaded =
          Botan::PKCS8::load_key(data_src, passphrase);
 
-      result.confirm("recovered private key from encrypted blob", loaded.get() != nullptr);
+      result.confirm("recovered private key from encrypted blob", loaded != nullptr);
       result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name());
       result.test_eq("reloaded key has same encoding", loaded->private_key_info(), pkcs8);
       }
@@ -643,7 +643,7 @@ void test_pbe_roundtrip(Test::Result& result,
       std::unique_ptr<Botan::Private_Key> loaded =
          Botan::PKCS8::load_key(data_src, passphrase);
 
-      result.confirm("recovered private key from BER blob", loaded.get() != nullptr);
+      result.confirm("recovered private key from BER blob", loaded != nullptr);
       result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name());
       result.test_eq("reloaded key has same encoding", loaded->private_key_info(), pkcs8);
       }
@@ -710,7 +710,7 @@ std::vector<Test::Result> PK_Key_Generation_Test::run()
             Botan::DataSource_Memory data_src(Botan::X509::PEM_encode(key));
             std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src));
 
-            result.confirm("recovered public key from private", loaded.get() != nullptr);
+            result.confirm("recovered public key from private", loaded != nullptr);
             result.test_eq("public key has same type", loaded->algo_name(), key.algo_name());
 
             try
@@ -731,7 +731,7 @@ std::vector<Test::Result> PK_Key_Generation_Test::run()
             Botan::DataSource_Memory data_src(ber);
             std::unique_ptr<Botan::Public_Key> loaded(Botan::X509::load_key(data_src));
 
-            result.confirm("recovered public key from private", loaded.get() != nullptr);
+            result.confirm("recovered public key from private", loaded != nullptr);
             result.test_eq("public key has same type", loaded->algo_name(), key.algo_name());
             result.test_eq("public key has same encoding", loaded->subject_public_key(), ber);
             }
@@ -748,7 +748,7 @@ std::vector<Test::Result> PK_Key_Generation_Test::run()
             std::unique_ptr<Botan::Private_Key> loaded =
                Botan::PKCS8::load_key(data_src);
 
-            result.confirm("recovered private key from PEM blob", loaded.get() != nullptr);
+            result.confirm("recovered private key from PEM blob", loaded != nullptr);
             result.test_eq("reloaded key has same type", loaded->algo_name(), key.algo_name());
             result.test_eq("reloaded key has same encoding", loaded->private_key_info(), ber);
             }
@@ -762,7 +762,7 @@ std::vector<Test::Result> PK_Key_Generation_Test::run()
             Botan::DataSource_Memory data_src(Botan::PKCS8::BER_encode(key));
             std::unique_ptr<Botan::Public_Key> loaded = Botan::PKCS8::load_key(data_src);
 
-            result.confirm("recovered public key from private", loaded.get() != nullptr);
+            result.confirm("recovered public key from private", loaded != nullptr);
             result.test_eq("public key has same type", loaded->algo_name(), key.algo_name());
             }
          catch(std::exception& e)
diff --git a/src/tests/test_tests.cpp b/src/tests/test_tests.cpp
index 2402cf46e..8cdb1381c 100644
--- a/src/tests/test_tests.cpp
+++ b/src/tests/test_tests.cpp
@@ -32,7 +32,7 @@ class Test_Tests final : public Test
          // Test a few success corner cases first
          const std::string testcase_name = "Failing Test";
 
-         result.test_throws("throws pi", []() { throw 3.14159; });
+         result.test_throws("throws pi", []() { throw 3.14159; }); // NOLINT(hicpp-exception-baseclass)
 
          // Test expected failure cases
             {
@@ -150,7 +150,7 @@ class Test_Tests final : public Test
             {
             Test::Result test_result(testcase_name);
             test_result.test_throws("test_throws", "expected msg",
-                                    []() { throw std::string("not even a std::exception"); });
+                                    []() { throw std::string("not even a std::exception"); }); // NOLINT(hicpp-exception-baseclass)
             verify_failure("test_throws 3", result, test_result);
             }
 
diff --git a/src/tests/test_thread_utils.cpp b/src/tests/test_thread_utils.cpp
index 051c63326..ea5878589 100644
--- a/src/tests/test_thread_utils.cpp
+++ b/src/tests/test_thread_utils.cpp
@@ -29,7 +29,7 @@ Test::Result thread_pool()
       std::this_thread::sleep_for(std::chrono::milliseconds((x*97)%127));
 
       if(x % 2 == 0)
-         throw x;
+         throw x; // NOLINT(hicpp-exception-baseclass)
       return x;
       };
 
diff --git a/src/tests/test_tls_transcript_hash_13.cpp b/src/tests/test_tls_transcript_hash_13.cpp
index 9aef7bc6f..35b52845f 100644
--- a/src/tests/test_tls_transcript_hash_13.cpp
+++ b/src/tests/test_tls_transcript_hash_13.cpp
@@ -183,7 +183,7 @@ std::vector<Test::Result> transcript_hash()
          {
          Transcript_Hash_State h1;
 
-         const auto truncation_mark = 477u;
+         const size_t truncation_mark = 477;
          auto truncated_ch = psk_client_hello;
          truncated_ch.resize(truncation_mark);
 
diff --git a/src/tests/unit_ecdsa.cpp b/src/tests/unit_ecdsa.cpp
index 4875a4c34..a9180bf32 100644
--- a/src/tests/unit_ecdsa.cpp
+++ b/src/tests/unit_ecdsa.cpp
@@ -266,7 +266,7 @@ Test::Result test_unusual_curve()
    Botan::DataSource_Memory key_data_src(key_odd_curve_str);
    std::unique_ptr<Botan::Private_Key> loaded_key = Botan::PKCS8::load_key(key_data_src);
 
-   result.confirm("reloaded key", loaded_key.get() != nullptr);
+   result.confirm("reloaded key", loaded_key != nullptr);
 
    return result;
    }
@@ -373,7 +373,7 @@ Test::Result test_ecc_key_with_rfc5915_extensions()
       Botan::DataSource_Stream key_stream(Test::data_file("x509/ecc/ecc_private_with_rfc5915_ext.pem"));
       std::unique_ptr<Botan::Private_Key> pkcs8 = Botan::PKCS8::load_key(key_stream);
 
-      result.confirm("loaded RFC 5915 key", pkcs8.get() != nullptr);
+      result.confirm("loaded RFC 5915 key", pkcs8 != nullptr);
       result.test_eq("key is ECDSA", pkcs8->algo_name(), "ECDSA");
       result.confirm("key type is ECDSA", dynamic_cast<Botan::ECDSA_PrivateKey*>(pkcs8.get()) != nullptr);
       }
@@ -394,7 +394,7 @@ Test::Result test_ecc_key_with_rfc5915_parameters()
       Botan::DataSource_Stream key_stream(Test::data_file("x509/ecc/ecc_private_with_rfc5915_parameters.pem"));
       auto pkcs8 = Botan::PKCS8::load_key(key_stream);
 
-      result.confirm("loaded RFC 5915 key", pkcs8.get() != nullptr);
+      result.confirm("loaded RFC 5915 key", pkcs8 != nullptr);
       result.test_eq("key is ECDSA", pkcs8->algo_name(), "ECDSA");
       result.confirm("key type is ECDSA", dynamic_cast<Botan::ECDSA_PrivateKey*>(pkcs8.get()) != nullptr);
       }