aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/exceptn.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-01-04 23:38:17 +0000
committerlloyd <[email protected]>2010-01-04 23:38:17 +0000
commit8a596fcdead165251ad32f7d0b6ce8c889675fba (patch)
treeb73099c3c89f1a1cb98c70befc128e82901dd000 /src/utils/exceptn.h
parentc8c7a8fb27183dfaf24879aa2520049ab4977de4 (diff)
parent18075193f37bf4268a617a52a3848ea6206de489 (diff)
merge of 'a51f8d7dec78251a3a4ccf162b346c289fc1d72a'
and 'aafa02a299b61c7762ae71dfc429396aa6bd25b3'
Diffstat (limited to 'src/utils/exceptn.h')
-rw-r--r--src/utils/exceptn.h134
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)
+ {}
};
}