aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/exceptn.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-02-24 02:18:55 +0000
committerlloyd <[email protected]>2010-02-24 02:18:55 +0000
commit6e50979c8d2a0635599228a2ae1a20d59b24a0c6 (patch)
tree587aaf6c20d45a6fa81ee180ca0aa533f51403d1 /src/utils/exceptn.h
parent888fc3d0f2f6f1dc5e9764e83e9b7fd64da916d8 (diff)
parent8c951ef2f1e54e1134e8db683662ec881df89c88 (diff)
propagate from branch 'net.randombit.botan' (head 84baf58b29f3aaaee34e2b873d0040be5a6c4368)
to branch 'net.randombit.botan.gost_3410' (head 63cbe3e357c071d7960bfedc31101eff35895285)
Diffstat (limited to 'src/utils/exceptn.h')
-rw-r--r--src/utils/exceptn.h145
1 files changed, 66 insertions, 79 deletions
diff --git a/src/utils/exceptn.h b/src/utils/exceptn.h
index a55d842bc..86efebc7c 100644
--- a/src/utils/exceptn.h
+++ b/src/utils/exceptn.h
@@ -1,6 +1,6 @@
/*
* Exceptions
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -9,32 +9,44 @@
#define BOTAN_EXCEPTION_H__
#include <botan/types.h>
+#include <botan/parsing.h>
#include <exception>
+#include <stdexcept>
#include <string>
namespace Botan {
+typedef std::runtime_error Exception;
+typedef std::invalid_argument Invalid_Argument;
+
/*
-* Exception Base Class
+* Invalid_State Exception
*/
-class BOTAN_DLL Exception : public std::exception
+struct BOTAN_DLL Invalid_State : public Exception
{
- public:
- 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;
+ Invalid_State(const std::string& err) :
+ Exception(err)
+ {}
};
/*
-* Invalid_Argument Exception
+* Lookup_Error Exception
*/
-struct BOTAN_DLL Invalid_Argument : public Exception
+struct BOTAN_DLL Lookup_Error : public Exception
{
- Invalid_Argument(const std::string& err = "") : Exception(err) {}
+ Lookup_Error(const std::string& err) :
+ Exception(err)
+ {}
+ };
+
+/*
+* Internal_Error Exception
+*/
+struct BOTAN_DLL Internal_Error : public Exception
+ {
+ Internal_Error(const std::string& err) :
+ Exception("Internal error: " + err)
+ {}
};
/*
@@ -42,7 +54,10 @@ struct BOTAN_DLL Invalid_Argument : public Exception
*/
struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument
{
- Invalid_Key_Length(const std::string&, u32bit);
+ Invalid_Key_Length(const std::string& name, u32bit length) :
+ Invalid_Argument(name + " cannot accept a key of length " +
+ to_string(length))
+ {}
};
/*
@@ -50,7 +65,11 @@ struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument
*/
struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument
{
- Invalid_Block_Size(const std::string&, const std::string&);
+ Invalid_Block_Size(const std::string& mode,
+ const std::string& pad) :
+ Invalid_Argument("Padding method " + pad +
+ " cannot be used with " + mode)
+ {}
};
/*
@@ -58,15 +77,10 @@ struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument
*/
struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument
{
- Invalid_IV_Length(const std::string&, u32bit);
- };
-
-/*
-* Invalid_State Exception
-*/
-struct BOTAN_DLL Invalid_State : public Exception
- {
- Invalid_State(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)
+ {}
};
/*
@@ -75,7 +89,8 @@ struct BOTAN_DLL Invalid_State : public Exception
struct BOTAN_DLL PRNG_Unseeded : public Invalid_State
{
PRNG_Unseeded(const std::string& algo) :
- Invalid_State("PRNG not seeded: " + algo) {}
+ Invalid_State("PRNG not seeded: " + algo)
+ {}
};
/*
@@ -84,57 +99,46 @@ struct BOTAN_DLL PRNG_Unseeded : public Invalid_State
struct BOTAN_DLL Policy_Violation : public Invalid_State
{
Policy_Violation(const std::string& err) :
- Invalid_State("Policy violation: " + err) {}
- };
-
-/*
-* Lookup_Error Exception
-*/
-struct BOTAN_DLL Lookup_Error : public Exception
- {
- Lookup_Error(const std::string& err) : Exception(err) {}
+ Invalid_State("Policy violation: " + err)
+ {}
};
/*
* Algorithm_Not_Found Exception
*/
-struct BOTAN_DLL Algorithm_Not_Found : public Exception
+struct BOTAN_DLL Algorithm_Not_Found : public Lookup_Error
{
- Algorithm_Not_Found(const std::string&);
- };
-
-/*
-* Format_Error Exception
-*/
-struct BOTAN_DLL Format_Error : public Exception
- {
- Format_Error(const std::string& err = "") : Exception(err) {}
+ Algorithm_Not_Found(const std::string& name) :
+ Lookup_Error("Could not find any algorithm named \"" + name + "\"")
+ {}
};
/*
* Invalid_Algorithm_Name Exception
*/
-struct BOTAN_DLL Invalid_Algorithm_Name : public Format_Error
+struct BOTAN_DLL Invalid_Algorithm_Name : public Invalid_Argument
{
- Invalid_Algorithm_Name(const std::string&);
+ Invalid_Algorithm_Name(const std::string& name):
+ Invalid_Argument("Invalid algorithm name: " + name)
+ {}
};
/*
* Encoding_Error Exception
*/
-struct BOTAN_DLL Encoding_Error : public Format_Error
+struct BOTAN_DLL Encoding_Error : public Invalid_Argument
{
Encoding_Error(const std::string& name) :
- Format_Error("Encoding error: " + name) {}
+ Invalid_Argument("Encoding error: " + name) {}
};
/*
* Decoding_Error Exception
*/
-struct BOTAN_DLL Decoding_Error : public Format_Error
+struct BOTAN_DLL Decoding_Error : public Invalid_Argument
{
Decoding_Error(const std::string& name) :
- Format_Error("Decoding error: " + name) {}
+ Invalid_Argument("Decoding error: " + name) {}
};
/*
@@ -152,44 +156,27 @@ 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)
+ {}
};
/*
-* Configuration Error 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);
- };
-
-/*
-* Integrity Failure Exception
-*/
-struct BOTAN_DLL Integrity_Failure : public Exception
- {
- Integrity_Failure(const std::string& err) :
- Exception("Integrity failure: " + err) {}
- };
-
-/*
-* Internal_Error Exception
+* Self Test Failure Exception
*/
-struct BOTAN_DLL Internal_Error : public Exception
+struct BOTAN_DLL Self_Test_Failure : public Internal_Error
{
- Internal_Error(const std::string& err) :
- Exception("Internal error: " + err) {}
+ Self_Test_Failure(const std::string& err) :
+ Internal_Error("Self test failed: " + err)
+ {}
};
/*
-* Self Test Failure Exception
+* Memory Allocation Exception
*/
-struct BOTAN_DLL Self_Test_Failure : public Internal_Error
+struct BOTAN_DLL Memory_Exhaustion : public std::bad_alloc
{
- Self_Test_Failure(const std::string& err) :
- Internal_Error("Self test failed: " + err) {}
+ const char* what() const throw()
+ { return "Ran out of memory, allocation failed"; }
};
}