From 26517eb98af4c3bb1faf38653ab55ae0956578eb Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Tue, 3 Oct 2017 09:57:04 -0400 Subject: Avoid empty methods, use =default or add a comment Sonar --- src/lib/asn1/x509_dn.cpp | 7 ------- src/lib/asn1/x509_dn.h | 2 +- src/lib/base/buf_comp.h | 2 +- src/lib/base/sym_algo.h | 2 +- src/lib/compression/compression.h | 6 +++--- src/lib/entropy/entropy_src.h | 8 +++----- src/lib/filters/basefilt.h | 2 +- src/lib/filters/filter.h | 4 ++-- src/lib/hash/comb4p/comb4p.h | 2 +- src/lib/math/numbertheory/pow_mod.h | 2 +- src/lib/modes/mode_pad/mode_pad.h | 5 ++++- src/lib/prov/pkcs11/p11_randomgenerator.h | 3 --- src/lib/prov/tpm/tpm.h | 2 -- src/lib/rng/rdrand_rng/rdrand_rng.h | 2 -- src/lib/rng/rng.h | 2 ++ src/lib/rng/system_rng/system_rng.cpp | 8 ++++---- src/lib/tls/tls_handshake_msg.h | 2 +- src/lib/tls/tls_seq_numbers.h | 2 +- src/lib/tls/tls_session_manager.h | 2 +- src/lib/utils/database.h | 4 ++-- src/tests/tests.h | 1 - 21 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/lib/asn1/x509_dn.cpp b/src/lib/asn1/x509_dn.cpp index a7ceeef4c..dd92b25ec 100644 --- a/src/lib/asn1/x509_dn.cpp +++ b/src/lib/asn1/x509_dn.cpp @@ -16,13 +16,6 @@ namespace Botan { -/* -* Create an empty X509_DN -*/ -X509_DN::X509_DN() - { - } - /* * Create an X509_DN */ diff --git a/src/lib/asn1/x509_dn.h b/src/lib/asn1/x509_dn.h index eb2682b10..09f8cf16b 100644 --- a/src/lib/asn1/x509_dn.h +++ b/src/lib/asn1/x509_dn.h @@ -39,7 +39,7 @@ class BOTAN_PUBLIC_API(2,0) X509_DN final : public ASN1_Object bool empty() const { return m_dn_info.empty(); } - X509_DN(); + X509_DN() = default; explicit X509_DN(const std::multimap&); explicit X509_DN(const std::multimap&); private: diff --git a/src/lib/base/buf_comp.h b/src/lib/base/buf_comp.h index b4e1eb7a1..a6cc84ba3 100644 --- a/src/lib/base/buf_comp.h +++ b/src/lib/base/buf_comp.h @@ -163,7 +163,7 @@ class BOTAN_PUBLIC_API(2,0) Buffered_Computation return final(); } - virtual ~Buffered_Computation() {} + virtual ~Buffered_Computation() = default; private: /** * Add more data to the computation diff --git a/src/lib/base/sym_algo.h b/src/lib/base/sym_algo.h index 7dbf600f8..a596f5932 100644 --- a/src/lib/base/sym_algo.h +++ b/src/lib/base/sym_algo.h @@ -21,7 +21,7 @@ namespace Botan { class BOTAN_PUBLIC_API(2,0) SymmetricAlgorithm { public: - virtual ~SymmetricAlgorithm() {} + virtual ~SymmetricAlgorithm() = default; /** * Reset the state. diff --git a/src/lib/compression/compression.h b/src/lib/compression/compression.h index ac1de5774..2ebde3f2f 100644 --- a/src/lib/compression/compression.h +++ b/src/lib/compression/compression.h @@ -56,7 +56,7 @@ class BOTAN_PUBLIC_API(2,0) Compression_Algorithm */ virtual void clear() = 0; - virtual ~Compression_Algorithm() {} + virtual ~Compression_Algorithm() = default; }; /* @@ -97,7 +97,7 @@ class BOTAN_PUBLIC_API(2,0) Decompression_Algorithm */ virtual void clear() = 0; - virtual ~Decompression_Algorithm() {} + virtual ~Decompression_Algorithm() = default; }; BOTAN_PUBLIC_API(2,0) Compression_Algorithm* make_compressor(const std::string& type); @@ -109,7 +109,7 @@ BOTAN_PUBLIC_API(2,0) Decompression_Algorithm* make_decompressor(const std::stri class Compression_Stream { public: - virtual ~Compression_Stream() {} + virtual ~Compression_Stream() = default; virtual void next_in(uint8_t* b, size_t len) = 0; diff --git a/src/lib/entropy/entropy_src.h b/src/lib/entropy/entropy_src.h index babdd20dd..56e5bd53e 100644 --- a/src/lib/entropy/entropy_src.h +++ b/src/lib/entropy/entropy_src.h @@ -45,14 +45,12 @@ class BOTAN_PUBLIC_API(2,0) Entropy_Source */ virtual size_t poll(RandomNumberGenerator& rng) = 0; + Entropy_Source() = default; Entropy_Source(const Entropy_Source& other) = delete; Entropy_Source(Entropy_Source&& other) = delete; Entropy_Source& operator=(const Entropy_Source& other) = delete; - virtual ~Entropy_Source() {} - - protected: - Entropy_Source() {} + virtual ~Entropy_Source() = default; }; class BOTAN_PUBLIC_API(2,0) Entropy_Sources final @@ -73,7 +71,7 @@ class BOTAN_PUBLIC_API(2,0) Entropy_Sources final */ size_t poll_just(RandomNumberGenerator& rng, const std::string& src); - Entropy_Sources() {} + Entropy_Sources() = default; explicit Entropy_Sources(const std::vector& sources); Entropy_Sources(const Entropy_Sources& other) = delete; diff --git a/src/lib/filters/basefilt.h b/src/lib/filters/basefilt.h index 9f64ebcdb..c3a45e28c 100644 --- a/src/lib/filters/basefilt.h +++ b/src/lib/filters/basefilt.h @@ -23,7 +23,7 @@ namespace Botan { class BOTAN_PUBLIC_API(2,0) BitBucket final : public Filter { public: - void write(const uint8_t[], size_t) override {} + void write(const uint8_t[], size_t) override { /* discard */ } std::string name() const override { return "BitBucket"; } }; diff --git a/src/lib/filters/filter.h b/src/lib/filters/filter.h index 773552b77..a0857c589 100644 --- a/src/lib/filters/filter.h +++ b/src/lib/filters/filter.h @@ -37,13 +37,13 @@ class BOTAN_PUBLIC_API(2,0) Filter * Start a new message. Must be closed by end_msg() before another * message can be started. */ - virtual void start_msg() {} + virtual void start_msg() { /* default empty */ } /** * Notify that the current message is finished; flush buffers and * do end-of-message processing (if any). */ - virtual void end_msg() {} + virtual void end_msg() { /* default empty */ } /** * Check whether this filter is an attachable filter. diff --git a/src/lib/hash/comb4p/comb4p.h b/src/lib/hash/comb4p/comb4p.h index 5d25ff3ad..6e47151bd 100644 --- a/src/lib/hash/comb4p/comb4p.h +++ b/src/lib/hash/comb4p/comb4p.h @@ -46,7 +46,7 @@ class BOTAN_PUBLIC_API(2,0) Comb4P final : public HashFunction void clear() override; private: - Comb4P() {} + Comb4P() = default; void add_data(const uint8_t input[], size_t length) override; void final_result(uint8_t out[]) override; diff --git a/src/lib/math/numbertheory/pow_mod.h b/src/lib/math/numbertheory/pow_mod.h index cca99b714..077f4ccf7 100644 --- a/src/lib/math/numbertheory/pow_mod.h +++ b/src/lib/math/numbertheory/pow_mod.h @@ -93,7 +93,7 @@ class BOTAN_PUBLIC_API(2,0) Power_Mod Usage_Hints hints = NO_HINTS, bool disable_montgomery_arith = false); Power_Mod(const Power_Mod&); - virtual ~Power_Mod() {} + virtual ~Power_Mod() = default; private: mutable std::unique_ptr m_core; }; diff --git a/src/lib/modes/mode_pad/mode_pad.h b/src/lib/modes/mode_pad/mode_pad.h index 4c539b181..cc196d251 100644 --- a/src/lib/modes/mode_pad/mode_pad.h +++ b/src/lib/modes/mode_pad/mode_pad.h @@ -136,7 +136,10 @@ class BOTAN_PUBLIC_API(2,0) ESP_Padding final : public BlockCipherModePaddingMet class BOTAN_PUBLIC_API(2,0) Null_Padding final : public BlockCipherModePaddingMethod { public: - void add_padding(secure_vector&, size_t, size_t) const override {} + void add_padding(secure_vector&, size_t, size_t) const override + { + /* no padding */ + } size_t unpad(const uint8_t[], size_t size) const override { return size; } diff --git a/src/lib/prov/pkcs11/p11_randomgenerator.h b/src/lib/prov/pkcs11/p11_randomgenerator.h index 8a74abf52..cab9b77c4 100644 --- a/src/lib/prov/pkcs11/p11_randomgenerator.h +++ b/src/lib/prov/pkcs11/p11_randomgenerator.h @@ -28,9 +28,6 @@ class BOTAN_PUBLIC_API(2,0) PKCS11_RNG final : public Hardware_RNG /// Initialize the RNG with the PKCS#11 session that provides access to the cryptoki functions explicit PKCS11_RNG(Session& session); - void clear() override - {} - std::string name() const override { return "PKCS11_RNG"; diff --git a/src/lib/prov/tpm/tpm.h b/src/lib/prov/tpm/tpm.h index fb4f027d5..802634056 100644 --- a/src/lib/prov/tpm/tpm.h +++ b/src/lib/prov/tpm/tpm.h @@ -92,8 +92,6 @@ class BOTAN_PUBLIC_API(2,0) TPM_RNG final : public Hardware_RNG bool is_seeded() const override { return true; } - void clear() override {} - private: TPM_Context& m_ctx; }; diff --git a/src/lib/rng/rdrand_rng/rdrand_rng.h b/src/lib/rng/rdrand_rng/rdrand_rng.h index c4cfbdc5c..377de419f 100644 --- a/src/lib/rng/rdrand_rng/rdrand_rng.h +++ b/src/lib/rng/rdrand_rng/rdrand_rng.h @@ -54,8 +54,6 @@ class BOTAN_PUBLIC_API(2,0) RDRAND_RNG final : public Hardware_RNG std::string name() const override { return "RDRAND"; } bool is_seeded() const override { return true; } - - void clear() override {} }; } diff --git a/src/lib/rng/rng.h b/src/lib/rng/rng.h index 75c5b4e78..34f62d1ff 100644 --- a/src/lib/rng/rng.h +++ b/src/lib/rng/rng.h @@ -178,6 +178,8 @@ typedef RandomNumberGenerator RNG; */ class BOTAN_PUBLIC_API(2,0) Hardware_RNG : public RandomNumberGenerator { + public: + virtual void clear() final { /* no way to clear state of hardware RNG */ } }; /** diff --git a/src/lib/rng/system_rng/system_rng.cpp b/src/lib/rng/system_rng/system_rng.cpp index fe9ae0f28..cec3deab1 100644 --- a/src/lib/rng/system_rng/system_rng.cpp +++ b/src/lib/rng/system_rng/system_rng.cpp @@ -64,7 +64,7 @@ class System_RNG_Impl final : public RandomNumberGenerator } bool is_seeded() const override { return true; } - void clear() override {} + void clear() override { /* not possible */ } std::string name() const override { return "cryptoapi"; } private: HCRYPTPROV m_prov; @@ -103,7 +103,7 @@ class System_RNG_Impl final : public RandomNumberGenerator } bool is_seeded() const override { return true; } - void clear() override {} + void clear() override { /* not possible */ } std::string name() const override { return "crypto_ng"; } private: BCRYPT_ALG_HANDLE m_handle; @@ -123,7 +123,7 @@ class System_RNG_Impl final : public RandomNumberGenerator void add_entropy(const uint8_t[], size_t) override { /* ignored */ } bool is_seeded() const override { return true; } - void clear() override {} + void clear() override { /* not possible */ } std::string name() const override { return "arc4random"; } }; @@ -162,7 +162,7 @@ class System_RNG_Impl final : public RandomNumberGenerator void randomize(uint8_t buf[], size_t len) override; void add_entropy(const uint8_t in[], size_t length) override; bool is_seeded() const override { return true; } - void clear() override {} + void clear() override { /* not possible */ } std::string name() const override { return BOTAN_SYSTEM_RNG_DEVICE; } private: int m_fd; diff --git a/src/lib/tls/tls_handshake_msg.h b/src/lib/tls/tls_handshake_msg.h index 394f0fa70..a0d9346fb 100644 --- a/src/lib/tls/tls_handshake_msg.h +++ b/src/lib/tls/tls_handshake_msg.h @@ -41,7 +41,7 @@ class BOTAN_PUBLIC_API(2,0) Handshake_Message */ virtual std::vector serialize() const = 0; - virtual ~Handshake_Message() {} + virtual ~Handshake_Message() = default; }; } diff --git a/src/lib/tls/tls_seq_numbers.h b/src/lib/tls/tls_seq_numbers.h index 3f08f27cb..817b5b6ed 100644 --- a/src/lib/tls/tls_seq_numbers.h +++ b/src/lib/tls/tls_seq_numbers.h @@ -18,7 +18,7 @@ namespace TLS { class Connection_Sequence_Numbers { public: - virtual ~Connection_Sequence_Numbers() {} + virtual ~Connection_Sequence_Numbers() = default; virtual void new_read_cipher_state() = 0; virtual void new_write_cipher_state() = 0; diff --git a/src/lib/tls/tls_session_manager.h b/src/lib/tls/tls_session_manager.h index e6b5a3194..40ca48f71 100644 --- a/src/lib/tls/tls_session_manager.h +++ b/src/lib/tls/tls_session_manager.h @@ -76,7 +76,7 @@ class BOTAN_PUBLIC_API(2,0) Session_Manager */ virtual std::chrono::seconds session_lifetime() const = 0; - virtual ~Session_Manager() {} + virtual ~Session_Manager() = default; }; /** diff --git a/src/lib/utils/database.h b/src/lib/utils/database.h index eb59cc376..a90e9fbfd 100644 --- a/src/lib/utils/database.h +++ b/src/lib/utils/database.h @@ -51,7 +51,7 @@ class BOTAN_PUBLIC_API(2,0) SQL_Database /* Maybe update */ virtual bool step() = 0; - virtual ~Statement() {} + virtual ~Statement() = default; }; /* @@ -64,7 +64,7 @@ class BOTAN_PUBLIC_API(2,0) SQL_Database virtual void create_table(const std::string& table_schema) = 0; - virtual ~SQL_Database() {} + virtual ~SQL_Database() = default; }; } diff --git a/src/tests/tests.h b/src/tests/tests.h index 4a32cc417..d8573444a 100644 --- a/src/tests/tests.h +++ b/src/tests/tests.h @@ -50,7 +50,6 @@ class Test_Error final : public Botan::Exception class Provider_Filter final { public: - Provider_Filter() {} void set(const std::string& provider) { m_provider = provider; } std::vector filter(const std::vector&) const; private: -- cgit v1.2.3