diff options
author | Jack Lloyd <[email protected]> | 2017-09-30 11:28:02 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-09-30 11:28:02 -0400 |
commit | f6dc3db8bb7e31569ed1a6042771e3f529aefab8 (patch) | |
tree | 9604495c046e1e52cc1d8e552879f04fe8599631 /src/lib | |
parent | e6dfcaa00d82a2fff5973bd2721dc09562d64199 (diff) |
Use class instead of struct for objects with member functions
Flagged by Sonar and quite reasonable
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/asn1/asn1_obj.h | 12 | ||||
-rw-r--r-- | src/lib/ffi/ffi_cipher.cpp | 7 | ||||
-rw-r--r-- | src/lib/ffi/ffi_util.h | 4 | ||||
-rw-r--r-- | src/lib/filters/basefilt.h | 7 | ||||
-rw-r--r-- | src/lib/filters/pipe.h | 19 | ||||
-rw-r--r-- | src/lib/math/ec_gfp/point_gfp.h | 16 | ||||
-rw-r--r-- | src/lib/pubkey/mce/code_based_key_gen.cpp | 2 | ||||
-rw-r--r-- | src/lib/pubkey/mce/polyn_gf2m.h | 2 | ||||
-rw-r--r-- | src/lib/pubkey/pkcs8.h | 7 | ||||
-rw-r--r-- | src/lib/tls/tls_exceptn.h | 7 | ||||
-rw-r--r-- | src/lib/utils/calendar.h | 71 | ||||
-rw-r--r-- | src/lib/utils/exceptn.h | 174 | ||||
-rw-r--r-- | src/lib/utils/http_util/http_util.h | 11 |
13 files changed, 183 insertions, 156 deletions
diff --git a/src/lib/asn1/asn1_obj.h b/src/lib/asn1/asn1_obj.h index 65a4919fd..63c7dc2e3 100644 --- a/src/lib/asn1/asn1_obj.h +++ b/src/lib/asn1/asn1_obj.h @@ -115,18 +115,20 @@ bool maybe_BER(DataSource& src); /** * General BER Decoding Error Exception */ -struct BOTAN_PUBLIC_API(2,0) BER_Decoding_Error : public Decoding_Error +class BOTAN_PUBLIC_API(2,0) BER_Decoding_Error : public Decoding_Error { - explicit BER_Decoding_Error(const std::string&); + public: + explicit BER_Decoding_Error(const std::string&); }; /** * Exception For Incorrect BER Taggings */ -struct BOTAN_PUBLIC_API(2,0) BER_Bad_Tag final : public BER_Decoding_Error +class BOTAN_PUBLIC_API(2,0) BER_Bad_Tag final : public BER_Decoding_Error { - BER_Bad_Tag(const std::string& msg, ASN1_Tag tag); - BER_Bad_Tag(const std::string& msg, ASN1_Tag tag1, ASN1_Tag tag2); + public: + BER_Bad_Tag(const std::string& msg, ASN1_Tag tag); + BER_Bad_Tag(const std::string& msg, ASN1_Tag tag1, ASN1_Tag tag2); }; } diff --git a/src/lib/ffi/ffi_cipher.cpp b/src/lib/ffi/ffi_cipher.cpp index 23e277166..44e42aa29 100644 --- a/src/lib/ffi/ffi_cipher.cpp +++ b/src/lib/ffi/ffi_cipher.cpp @@ -12,10 +12,11 @@ extern "C" { using namespace Botan_FFI; -struct botan_cipher_struct final : public botan_struct<Botan::Cipher_Mode, 0xB4A2BF9C> +class botan_cipher_struct final : public botan_struct<Botan::Cipher_Mode, 0xB4A2BF9C> { - explicit botan_cipher_struct(Botan::Cipher_Mode* x) : botan_struct(x) {} - Botan::secure_vector<uint8_t> m_buf; + public: + explicit botan_cipher_struct(Botan::Cipher_Mode* x) : botan_struct(x) {} + Botan::secure_vector<uint8_t> m_buf; }; int botan_cipher_init(botan_cipher_t* cipher, const char* cipher_name, uint32_t flags) diff --git a/src/lib/ffi/ffi_util.h b/src/lib/ffi/ffi_util.h index 7f959259c..eb6d22786 100644 --- a/src/lib/ffi/ffi_util.h +++ b/src/lib/ffi/ffi_util.h @@ -25,7 +25,7 @@ class FFI_Error final : public Botan::Exception }; template<typename T, uint32_t MAGIC> -struct botan_struct +class botan_struct { public: botan_struct(T* obj) : m_magic(MAGIC), m_obj(obj) {} @@ -46,7 +46,7 @@ struct botan_struct }; #define BOTAN_FFI_DECLARE_STRUCT(NAME, TYPE, MAGIC) \ - struct NAME final : public botan_struct<TYPE, MAGIC> { explicit NAME(TYPE* x) : botan_struct(x) {} } + class NAME final : public botan_struct<TYPE, MAGIC> { public: explicit NAME(TYPE* x) : botan_struct(x) {} } // Declared in ffi.cpp int ffi_error_exception_thrown(const char* func_name, const char* exn); diff --git a/src/lib/filters/basefilt.h b/src/lib/filters/basefilt.h index 40ce0ec6e..01bcad756 100644 --- a/src/lib/filters/basefilt.h +++ b/src/lib/filters/basefilt.h @@ -20,11 +20,12 @@ namespace Botan { /** * BitBucket is a filter which simply discards all inputs */ -struct BOTAN_PUBLIC_API(2,0) BitBucket final : public Filter +class BOTAN_PUBLIC_API(2,0) BitBucket final : public Filter { - void write(const uint8_t[], size_t) override {} + public: + void write(const uint8_t[], size_t) override {} - std::string name() const override { return "BitBucket"; } + std::string name() const override { return "BitBucket"; } }; /** diff --git a/src/lib/filters/pipe.h b/src/lib/filters/pipe.h index 060b5c1ca..cd446bd7e 100644 --- a/src/lib/filters/pipe.h +++ b/src/lib/filters/pipe.h @@ -38,16 +38,17 @@ class BOTAN_PUBLIC_API(2,0) Pipe final : public DataSource * Exception if you use an invalid message as an argument to * read, remaining, etc */ - struct BOTAN_PUBLIC_API(2,0) Invalid_Message_Number final : public Invalid_Argument + class BOTAN_PUBLIC_API(2,0) Invalid_Message_Number final : public Invalid_Argument { - /** - * @param where the error occurred - * @param msg the invalid message id that was used - */ - Invalid_Message_Number(const std::string& where, message_id msg) : - Invalid_Argument("Pipe::" + where + ": Invalid message number " + - std::to_string(msg)) - {} + public: + /** + * @param where the error occurred + * @param msg the invalid message id that was used + */ + Invalid_Message_Number(const std::string& where, message_id msg) : + Invalid_Argument("Pipe::" + where + ": Invalid message number " + + std::to_string(msg)) + {} }; /** diff --git a/src/lib/math/ec_gfp/point_gfp.h b/src/lib/math/ec_gfp/point_gfp.h index 1d36ad2f4..61239df80 100644 --- a/src/lib/math/ec_gfp/point_gfp.h +++ b/src/lib/math/ec_gfp/point_gfp.h @@ -19,20 +19,22 @@ namespace Botan { * Exception thrown if you try to convert a zero point to an affine * coordinate */ -struct BOTAN_PUBLIC_API(2,0) Illegal_Transformation final : public Exception +class BOTAN_PUBLIC_API(2,0) Illegal_Transformation final : public Exception { - explicit Illegal_Transformation(const std::string& err = - "Requested transformation is not possible") : - Exception(err) {} + public: + explicit Illegal_Transformation(const std::string& err = + "Requested transformation is not possible") : + Exception(err) {} }; /** * Exception thrown if some form of illegal point is decoded */ -struct BOTAN_PUBLIC_API(2,0) Illegal_Point final : public Exception +class BOTAN_PUBLIC_API(2,0) Illegal_Point final : public Exception { - explicit Illegal_Point(const std::string& err = "Malformed ECP point detected") : - Exception(err) {} + public: + explicit Illegal_Point(const std::string& err = "Malformed ECP point detected") : + Exception(err) {} }; /** diff --git a/src/lib/pubkey/mce/code_based_key_gen.cpp b/src/lib/pubkey/mce/code_based_key_gen.cpp index 7377bc117..01650af26 100644 --- a/src/lib/pubkey/mce/code_based_key_gen.cpp +++ b/src/lib/pubkey/mce/code_based_key_gen.cpp @@ -19,7 +19,7 @@ namespace Botan { namespace { -struct binary_matrix +class binary_matrix { public: binary_matrix(uint32_t m_rown, uint32_t m_coln); diff --git a/src/lib/pubkey/mce/polyn_gf2m.h b/src/lib/pubkey/mce/polyn_gf2m.h index 987e1cffe..dd7c1081c 100644 --- a/src/lib/pubkey/mce/polyn_gf2m.h +++ b/src/lib/pubkey/mce/polyn_gf2m.h @@ -20,7 +20,7 @@ namespace Botan { class RandomNumberGenerator; -struct polyn_gf2m +class polyn_gf2m { public: /** diff --git a/src/lib/pubkey/pkcs8.h b/src/lib/pubkey/pkcs8.h index c97fda0e3..0bc9a18f1 100644 --- a/src/lib/pubkey/pkcs8.h +++ b/src/lib/pubkey/pkcs8.h @@ -23,10 +23,11 @@ class RandomNumberGenerator; /** * PKCS #8 General Exception */ -struct BOTAN_PUBLIC_API(2,0) PKCS8_Exception final : public Decoding_Error +class BOTAN_PUBLIC_API(2,0) PKCS8_Exception final : public Decoding_Error { - explicit PKCS8_Exception(const std::string& error) : - Decoding_Error("PKCS #8: " + error) {} + public: + explicit PKCS8_Exception(const std::string& error) : + Decoding_Error("PKCS #8: " + error) {} }; /** diff --git a/src/lib/tls/tls_exceptn.h b/src/lib/tls/tls_exceptn.h index 1b58e1beb..572ff1885 100644 --- a/src/lib/tls/tls_exceptn.h +++ b/src/lib/tls/tls_exceptn.h @@ -34,10 +34,11 @@ class BOTAN_PUBLIC_API(2,0) TLS_Exception : public Exception /** * Unexpected_Message Exception */ -struct BOTAN_PUBLIC_API(2,0) Unexpected_Message final : public TLS_Exception +class BOTAN_PUBLIC_API(2,0) Unexpected_Message final : public TLS_Exception { - explicit Unexpected_Message(const std::string& err) : - TLS_Exception(Alert::UNEXPECTED_MESSAGE, err) {} + public: + explicit Unexpected_Message(const std::string& err) : + TLS_Exception(Alert::UNEXPECTED_MESSAGE, err) {} }; } diff --git a/src/lib/utils/calendar.h b/src/lib/utils/calendar.h index 5cf59eccc..665022599 100644 --- a/src/lib/utils/calendar.h +++ b/src/lib/utils/calendar.h @@ -18,50 +18,51 @@ namespace Botan { /** * Struct representing a particular date and time */ -struct BOTAN_PUBLIC_API(2,0) calendar_point +class BOTAN_PUBLIC_API(2,0) calendar_point { - /** The year */ - uint32_t year; + public: + /** The year */ + uint32_t year; - /** The month, 1 through 12 for Jan to Dec */ - uint32_t month; + /** The month, 1 through 12 for Jan to Dec */ + uint32_t month; - /** The day of the month, 1 through 31 (or 28 or 30 based on month */ - uint32_t day; + /** The day of the month, 1 through 31 (or 28 or 30 based on month */ + uint32_t day; - /** Hour in 24-hour form, 0 to 23 */ - uint32_t hour; + /** Hour in 24-hour form, 0 to 23 */ + uint32_t hour; - /** Minutes in the hour, 0 to 60 */ - uint32_t minutes; + /** Minutes in the hour, 0 to 60 */ + uint32_t minutes; - /** Seconds in the minute, 0 to 60, but might be slightly - larger to deal with leap seconds on some systems - */ - uint32_t seconds; + /** Seconds in the minute, 0 to 60, but might be slightly + larger to deal with leap seconds on some systems + */ + uint32_t seconds; - /** - * Initialize a calendar_point - * @param y the year - * @param mon the month - * @param d the day - * @param h the hour - * @param min the minute - * @param sec the second - */ - calendar_point(uint32_t y, uint32_t mon, uint32_t d, uint32_t h, uint32_t min, uint32_t sec) : - year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {} + /** + * Initialize a calendar_point + * @param y the year + * @param mon the month + * @param d the day + * @param h the hour + * @param min the minute + * @param sec the second + */ + calendar_point(uint32_t y, uint32_t mon, uint32_t d, uint32_t h, uint32_t min, uint32_t sec) : + year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {} - /** - * Returns an STL timepoint object - */ - std::chrono::system_clock::time_point to_std_timepoint() const; + /** + * Returns an STL timepoint object + */ + std::chrono::system_clock::time_point to_std_timepoint() const; - /** - * Returns a human readable string of the struct's components. - * Formatting might change over time. Currently it is RFC339 'iso-date-time'. - */ - std::string to_string() const; + /** + * Returns a human readable string of the struct's components. + * Formatting might change over time. Currently it is RFC339 'iso-date-time'. + */ + std::string to_string() const; }; /** diff --git a/src/lib/utils/exceptn.h b/src/lib/utils/exceptn.h index 5242e87d9..e5432e43b 100644 --- a/src/lib/utils/exceptn.h +++ b/src/lib/utils/exceptn.h @@ -49,202 +49,218 @@ class BOTAN_PUBLIC_API(2,0) Invalid_Argument : public Exception * An argument that is invalid because it is not supported by Botan. * It might or might not be valid in another context like a standard. */ -struct BOTAN_PUBLIC_API(2,0) Unsupported_Argument final : public Invalid_Argument +class BOTAN_PUBLIC_API(2,0) Unsupported_Argument final : public Invalid_Argument { - explicit Unsupported_Argument(const std::string& msg) : Invalid_Argument(msg) {} + public: + explicit Unsupported_Argument(const std::string& msg) : Invalid_Argument(msg) {} }; /** * Invalid_State Exception */ -struct BOTAN_PUBLIC_API(2,0) Invalid_State : public Exception +class BOTAN_PUBLIC_API(2,0) Invalid_State : public Exception { - explicit Invalid_State(const std::string& err) : - Exception(err) - {} + public: + explicit Invalid_State(const std::string& err) : Exception(err) {} }; /** * Lookup_Error Exception */ -struct BOTAN_PUBLIC_API(2,0) Lookup_Error : public Exception +class BOTAN_PUBLIC_API(2,0) Lookup_Error : public Exception { - explicit Lookup_Error(const std::string& err) : - Exception(err) - {} + public: + explicit Lookup_Error(const std::string& err) : Exception(err) {} - Lookup_Error(const std::string& type, - const std::string& algo, - const std::string& provider) : - Exception("Unavailable " + type + " " + algo + - (provider.empty() ? std::string("") : (" for provider " + provider))) - {} + Lookup_Error(const std::string& type, + const std::string& algo, + const std::string& provider) : + Exception("Unavailable " + type + " " + algo + + (provider.empty() ? std::string("") : (" for provider " + provider))) + {} }; /** * Internal_Error Exception */ -struct BOTAN_PUBLIC_API(2,0) Internal_Error : public Exception +class BOTAN_PUBLIC_API(2,0) Internal_Error : public Exception { - explicit Internal_Error(const std::string& err) : - Exception("Internal error: " + err) - {} + public: + explicit Internal_Error(const std::string& err) : + Exception("Internal error: " + err) + {} }; /** * Invalid_Key_Length Exception */ -struct BOTAN_PUBLIC_API(2,0) Invalid_Key_Length final : public Invalid_Argument +class BOTAN_PUBLIC_API(2,0) Invalid_Key_Length final : public Invalid_Argument { - Invalid_Key_Length(const std::string& name, size_t length) : - Invalid_Argument(name + " cannot accept a key of length " + - std::to_string(length)) - {} + public: + Invalid_Key_Length(const std::string& name, size_t length) : + Invalid_Argument(name + " cannot accept a key of length " + + std::to_string(length)) + {} }; /** * Invalid_IV_Length Exception */ -struct BOTAN_PUBLIC_API(2,0) Invalid_IV_Length final : public Invalid_Argument +class BOTAN_PUBLIC_API(2,0) Invalid_IV_Length final : public Invalid_Argument { - Invalid_IV_Length(const std::string& mode, size_t bad_len) : - Invalid_Argument("IV length " + std::to_string(bad_len) + - " is invalid for " + mode) - {} + public: + Invalid_IV_Length(const std::string& mode, size_t bad_len) : + Invalid_Argument("IV length " + std::to_string(bad_len) + + " is invalid for " + mode) + {} }; /** * PRNG_Unseeded Exception */ -struct BOTAN_PUBLIC_API(2,0) PRNG_Unseeded final : public Invalid_State +class BOTAN_PUBLIC_API(2,0) PRNG_Unseeded final : public Invalid_State { - explicit PRNG_Unseeded(const std::string& algo) : - Invalid_State("PRNG not seeded: " + algo) - {} + public: + explicit PRNG_Unseeded(const std::string& algo) : + Invalid_State("PRNG not seeded: " + algo) + {} }; /** * Policy_Violation Exception */ -struct BOTAN_PUBLIC_API(2,0) Policy_Violation final : public Invalid_State +class BOTAN_PUBLIC_API(2,0) Policy_Violation final : public Invalid_State { - explicit Policy_Violation(const std::string& err) : - Invalid_State("Policy violation: " + err) - {} + public: + explicit Policy_Violation(const std::string& err) : + Invalid_State("Policy violation: " + err) + {} }; /** * Algorithm_Not_Found Exception */ -struct BOTAN_PUBLIC_API(2,0) Algorithm_Not_Found final : public Lookup_Error +class BOTAN_PUBLIC_API(2,0) Algorithm_Not_Found final : public Lookup_Error { - explicit Algorithm_Not_Found(const std::string& name) : - Lookup_Error("Could not find any algorithm named \"" + name + "\"") - {} + public: + explicit Algorithm_Not_Found(const std::string& name) : + Lookup_Error("Could not find any algorithm named \"" + name + "\"") + {} }; /** * No_Provider_Found Exception */ -struct BOTAN_PUBLIC_API(2,0) No_Provider_Found final : public Exception +class BOTAN_PUBLIC_API(2,0) No_Provider_Found final : public Exception { - explicit No_Provider_Found(const std::string& name) : - Exception("Could not find any provider for algorithm named \"" + name + "\"") - {} + public: + explicit No_Provider_Found(const std::string& name) : + Exception("Could not find any provider for algorithm named \"" + name + "\"") + {} }; /** * Provider_Not_Found is thrown when a specific provider was requested * but that provider is not available. */ -struct BOTAN_PUBLIC_API(2,0) Provider_Not_Found final : public Lookup_Error +class BOTAN_PUBLIC_API(2,0) Provider_Not_Found final : public Lookup_Error { - Provider_Not_Found(const std::string& algo, const std::string& provider) : - Lookup_Error("Could not find provider '" + provider + "' for " + algo) {} + public: + Provider_Not_Found(const std::string& algo, const std::string& provider) : + Lookup_Error("Could not find provider '" + provider + "' for " + algo) {} }; /** * Invalid_Algorithm_Name Exception */ -struct BOTAN_PUBLIC_API(2,0) Invalid_Algorithm_Name final : public Invalid_Argument +class BOTAN_PUBLIC_API(2,0) Invalid_Algorithm_Name final : public Invalid_Argument { - explicit Invalid_Algorithm_Name(const std::string& name): - Invalid_Argument("Invalid algorithm name: " + name) - {} + public: + explicit Invalid_Algorithm_Name(const std::string& name): + Invalid_Argument("Invalid algorithm name: " + name) + {} }; /** * Encoding_Error Exception */ -struct BOTAN_PUBLIC_API(2,0) Encoding_Error final : public Invalid_Argument +class BOTAN_PUBLIC_API(2,0) Encoding_Error final : public Invalid_Argument { - explicit Encoding_Error(const std::string& name) : - Invalid_Argument("Encoding error: " + name) {} + public: + explicit Encoding_Error(const std::string& name) : + Invalid_Argument("Encoding error: " + name) {} }; /** * Decoding_Error Exception */ -struct BOTAN_PUBLIC_API(2,0) Decoding_Error : public Invalid_Argument +class BOTAN_PUBLIC_API(2,0) Decoding_Error : public Invalid_Argument { - explicit Decoding_Error(const std::string& name) : - Invalid_Argument("Decoding error: " + name) {} + public: + explicit Decoding_Error(const std::string& name) : + Invalid_Argument("Decoding error: " + name) {} }; /** * Integrity_Failure Exception */ -struct BOTAN_PUBLIC_API(2,0) Integrity_Failure final : public Exception +class BOTAN_PUBLIC_API(2,0) Integrity_Failure final : public Exception { - explicit Integrity_Failure(const std::string& msg) : - Exception("Integrity failure: " + msg) {} + public: + explicit Integrity_Failure(const std::string& msg) : + Exception("Integrity failure: " + msg) {} }; /** * Invalid_OID Exception */ -struct BOTAN_PUBLIC_API(2,0) Invalid_OID final : public Decoding_Error +class BOTAN_PUBLIC_API(2,0) Invalid_OID final : public Decoding_Error { - explicit Invalid_OID(const std::string& oid) : - Decoding_Error("Invalid ASN.1 OID: " + oid) {} + public: + explicit Invalid_OID(const std::string& oid) : + Decoding_Error("Invalid ASN.1 OID: " + oid) {} }; /** * Stream_IO_Error Exception */ -struct BOTAN_PUBLIC_API(2,0) Stream_IO_Error final : public Exception +class BOTAN_PUBLIC_API(2,0) Stream_IO_Error final : public Exception { - explicit Stream_IO_Error(const std::string& err) : - Exception("I/O error: " + err) - {} + public: + explicit Stream_IO_Error(const std::string& err) : + Exception("I/O error: " + err) + {} }; /** * No_Filesystem_Access Exception */ -struct BOTAN_PUBLIC_API(2,0) No_Filesystem_Access final : public Exception +class BOTAN_PUBLIC_API(2,0) No_Filesystem_Access final : public Exception { - No_Filesystem_Access() : Exception("No filesystem access enabled.") {} + public: + No_Filesystem_Access() : Exception("No filesystem access enabled.") {} }; /** * Self Test Failure Exception */ -struct BOTAN_PUBLIC_API(2,0) Self_Test_Failure final : public Internal_Error +class BOTAN_PUBLIC_API(2,0) Self_Test_Failure final : public Internal_Error { - explicit Self_Test_Failure(const std::string& err) : - Internal_Error("Self test failed: " + err) - {} + public: + explicit Self_Test_Failure(const std::string& err) : + Internal_Error("Self test failed: " + err) + {} }; /** * Not Implemented Exception */ -struct BOTAN_PUBLIC_API(2,0) Not_Implemented final : public Exception +class BOTAN_PUBLIC_API(2,0) Not_Implemented final : public Exception { - explicit Not_Implemented(const std::string& err) : - Exception("Not implemented", err) - {} + public: + explicit Not_Implemented(const std::string& err) : + Exception("Not implemented", err) + {} }; } diff --git a/src/lib/utils/http_util/http_util.h b/src/lib/utils/http_util/http_util.h index aa8e1cbc0..528a4fae8 100644 --- a/src/lib/utils/http_util/http_util.h +++ b/src/lib/utils/http_util/http_util.h @@ -19,7 +19,7 @@ namespace Botan { namespace HTTP { -struct Response +class Response { public: Response() : m_status_code(0), m_status_message("Uninitialized") {} @@ -56,11 +56,12 @@ struct Response /** * HTTP_Error Exception */ -struct BOTAN_PUBLIC_API(2,0) HTTP_Error final : public Exception +class BOTAN_PUBLIC_API(2,0) HTTP_Error final : public Exception { - explicit HTTP_Error(const std::string& msg) : - Exception("HTTP error " + msg) - {} + public: + explicit HTTP_Error(const std::string& msg) : + Exception("HTTP error " + msg) + {} }; BOTAN_PUBLIC_API(2,0) std::ostream& operator<<(std::ostream& o, const Response& resp); |