diff options
author | lloyd <[email protected]> | 2010-01-04 16:54:25 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-01-04 16:54:25 +0000 |
commit | 18075193f37bf4268a617a52a3848ea6206de489 (patch) | |
tree | 9f1e170380bdc87c973d0f69dfb62214c18bfc09 /src/utils/exceptn.h | |
parent | 57f0176410cb06488142e8fbef0f8cf9ece2e4a3 (diff) |
Remove Exception::set_msg. Inline all exception constructors.
Diffstat (limited to 'src/utils/exceptn.h')
-rw-r--r-- | src/utils/exceptn.h | 134 |
1 files changed, 85 insertions, 49 deletions
diff --git a/src/utils/exceptn.h b/src/utils/exceptn.h index a55d842bc..d106de1c0 100644 --- a/src/utils/exceptn.h +++ b/src/utils/exceptn.h @@ -9,7 +9,9 @@ #define BOTAN_EXCEPTION_H__ #include <botan/types.h> +#include <botan/parsing.h> #include <exception> +#include <stdexcept> #include <string> namespace Botan { @@ -20,11 +22,13 @@ namespace Botan { class BOTAN_DLL Exception : public std::exception { public: + Exception(const std::string& m = "Unknown error") : + msg("Botan: " + m) + {} + const char* what() const throw() { return msg.c_str(); } - Exception(const std::string& m = "Unknown error") { set_msg(m); } + virtual ~Exception() throw() {} - protected: - void set_msg(const std::string& m) { msg = "Botan: " + m; } private: std::string msg; }; @@ -34,81 +38,113 @@ class BOTAN_DLL Exception : public std::exception */ struct BOTAN_DLL Invalid_Argument : public Exception { - Invalid_Argument(const std::string& err = "") : Exception(err) {} + Invalid_Argument(const std::string& err = "") : + Exception(err) + {} }; /* -* Invalid_Key_Length Exception +* Invalid_State Exception */ -struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument +struct BOTAN_DLL Invalid_State : public Exception { - Invalid_Key_Length(const std::string&, u32bit); + Invalid_State(const std::string& err) : + Exception(err) + {} }; /* -* Invalid_Block_Size Exception +* Format_Error Exception */ -struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument +struct BOTAN_DLL Format_Error : public Exception { - Invalid_Block_Size(const std::string&, const std::string&); + Format_Error(const std::string& err = "") : + Exception(err) + {} }; /* -* Invalid_IV_Length Exception +* Lookup_Error Exception */ -struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument +struct BOTAN_DLL Lookup_Error : public Exception { - Invalid_IV_Length(const std::string&, u32bit); + Lookup_Error(const std::string& err) : + Exception(err) + {} }; /* -* Invalid_State Exception +* Internal_Error Exception */ -struct BOTAN_DLL Invalid_State : public Exception +struct BOTAN_DLL Internal_Error : public Exception { - Invalid_State(const std::string& err) : Exception(err) {} + Internal_Error(const std::string& err) : + Exception("Internal error: " + err) + {} }; /* -* PRNG_Unseeded Exception +* Invalid_Key_Length Exception */ -struct BOTAN_DLL PRNG_Unseeded : public Invalid_State +struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument { - PRNG_Unseeded(const std::string& algo) : - Invalid_State("PRNG not seeded: " + algo) {} + Invalid_Key_Length(const std::string& name, u32bit length) : + Invalid_Argument(name + " cannot accept a key of length " + + to_string(length)) + {} }; /* -* Policy_Violation Exception +* Invalid_Block_Size Exception */ -struct BOTAN_DLL Policy_Violation : public Invalid_State +struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument { - Policy_Violation(const std::string& err) : - Invalid_State("Policy violation: " + err) {} + Invalid_Block_Size(const std::string& mode, + const std::string& pad) : + Invalid_Argument("Padding method " + pad + + " cannot be used with " + mode) + {} }; /* -* Lookup_Error Exception +* Invalid_IV_Length Exception */ -struct BOTAN_DLL Lookup_Error : public Exception +struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument { - Lookup_Error(const std::string& err) : Exception(err) {} + Invalid_IV_Length(const std::string& mode, u32bit bad_len) : + Invalid_Argument("IV length " + to_string(bad_len) + + " is invalid for " + mode) + {} }; /* -* Algorithm_Not_Found Exception +* PRNG_Unseeded Exception */ -struct BOTAN_DLL Algorithm_Not_Found : public Exception +struct BOTAN_DLL PRNG_Unseeded : public Invalid_State { - Algorithm_Not_Found(const std::string&); + PRNG_Unseeded(const std::string& algo) : + Invalid_State("PRNG not seeded: " + algo) + {} }; /* -* Format_Error Exception +* Policy_Violation Exception */ -struct BOTAN_DLL Format_Error : public Exception +struct BOTAN_DLL Policy_Violation : public Invalid_State + { + Policy_Violation(const std::string& err) : + Invalid_State("Policy violation: " + err) + {} + }; + +/* +* Algorithm_Not_Found Exception +*/ +struct BOTAN_DLL Algorithm_Not_Found : public Lookup_Error { - Format_Error(const std::string& err = "") : Exception(err) {} + Algorithm_Not_Found(const std::string& name) : + Lookup_Error("Could not find any algorithm named \"" + name + "\"") + {} }; /* @@ -116,7 +152,9 @@ struct BOTAN_DLL Format_Error : public Exception */ struct BOTAN_DLL Invalid_Algorithm_Name : public Format_Error { - Invalid_Algorithm_Name(const std::string&); + Invalid_Algorithm_Name(const std::string& name): + Format_Error("Invalid algorithm name: " + name) + {} }; /* @@ -152,7 +190,8 @@ struct BOTAN_DLL Invalid_OID : public Decoding_Error struct BOTAN_DLL Stream_IO_Error : public Exception { Stream_IO_Error(const std::string& err) : - Exception("I/O error: " + err) {} + Exception("I/O error: " + err) + {} }; /* @@ -161,26 +200,22 @@ struct BOTAN_DLL Stream_IO_Error : public Exception struct BOTAN_DLL Config_Error : public Format_Error { Config_Error(const std::string& err) : - Format_Error("Config error: " + err) {} - Config_Error(const std::string&, u32bit); + Format_Error("Config error: " + err) + {} + + Config_Error(const std::string& err, u32bit line) : + Format_Error("Config error at line " + to_string(line) + ": " + err) + {} }; /* * Integrity Failure Exception */ -struct BOTAN_DLL Integrity_Failure : public Exception +struct BOTAN_DLL Integrity_Failure : public Internal_Error { Integrity_Failure(const std::string& err) : - Exception("Integrity failure: " + err) {} - }; - -/* -* Internal_Error Exception -*/ -struct BOTAN_DLL Internal_Error : public Exception - { - Internal_Error(const std::string& err) : - Exception("Internal error: " + err) {} + Internal_Error("Integrity failure: " + err) + {} }; /* @@ -189,7 +224,8 @@ struct BOTAN_DLL Internal_Error : public Exception struct BOTAN_DLL Self_Test_Failure : public Internal_Error { Self_Test_Failure(const std::string& err) : - Internal_Error("Self test failed: " + err) {} + Internal_Error("Self test failed: " + err) + {} }; } |