aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <lloyd@randombit.net>2010-01-04 16:54:25 +0000
committerlloyd <lloyd@randombit.net>2010-01-04 16:54:25 +0000
commit18075193f37bf4268a617a52a3848ea6206de489 (patch)
tree9f1e170380bdc87c973d0f69dfb62214c18bfc09 /src
parent57f0176410cb06488142e8fbef0f8cf9ece2e4a3 (diff)
Remove Exception::set_msg. Inline all exception constructors.
Diffstat (limited to 'src')
-rw-r--r--src/filters/pipe.cpp10
-rw-r--r--src/filters/pipe.h8
-rw-r--r--src/utils/exceptn.cpp62
-rw-r--r--src/utils/exceptn.h134
-rw-r--r--src/utils/info.txt1
5 files changed, 90 insertions, 125 deletions
diff --git a/src/filters/pipe.cpp b/src/filters/pipe.cpp
index 80b6f27aa..ad975a275 100644
--- a/src/filters/pipe.cpp
+++ b/src/filters/pipe.cpp
@@ -12,16 +12,6 @@
namespace Botan {
-/*
-* Constructor for Invalid_Message_Number
-*/
-Pipe::Invalid_Message_Number::Invalid_Message_Number(const std::string& where,
- message_id msg)
- {
- set_msg("Pipe::" + where + ": Invalid message number " +
- to_string(msg));
- }
-
namespace {
/*
diff --git a/src/filters/pipe.h b/src/filters/pipe.h
index ba17e7e68..9af21a13f 100644
--- a/src/filters/pipe.h
+++ b/src/filters/pipe.h
@@ -28,10 +28,12 @@ class BOTAN_DLL Pipe : public DataSource
public:
typedef u32bit message_id;
- class BOTAN_DLL Invalid_Message_Number : public Invalid_Argument
+ struct BOTAN_DLL Invalid_Message_Number : public Invalid_Argument
{
- public:
- Invalid_Message_Number(const std::string&, message_id);
+ Invalid_Message_Number(const std::string& where, message_id msg) :
+ Invalid_Argument("Pipe::" + where + ": Invalid message number " +
+ to_string(msg))
+ {}
};
static const message_id LAST_MESSAGE;
diff --git a/src/utils/exceptn.cpp b/src/utils/exceptn.cpp
deleted file mode 100644
index 753d63424..000000000
--- a/src/utils/exceptn.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-* Exceptions
-* (C) 1999-2007 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/exceptn.h>
-#include <botan/parsing.h>
-
-namespace Botan {
-
-/*
-* Constructor for Invalid_Key_Length
-*/
-Invalid_Key_Length::Invalid_Key_Length(const std::string& name, u32bit length)
- {
- set_msg(name + " cannot accept a key of length " + to_string(length));
- }
-
-/*
-* Constructor for Invalid_Block_Size
-*/
-Invalid_Block_Size::Invalid_Block_Size(const std::string& mode,
- const std::string& pad)
- {
- set_msg("Padding method " + pad + " cannot be used with " + mode);
- }
-
-/*
-* Constructor for Invalid_IV_Length
-*/
-Invalid_IV_Length::Invalid_IV_Length(const std::string& mode, u32bit bad_len)
- {
- set_msg("IV length " + to_string(bad_len) + " is invalid for " + mode);
- }
-
-/*
-* Constructor for Algorithm_Not_Found
-*/
-Algorithm_Not_Found::Algorithm_Not_Found(const std::string& name)
- {
- set_msg("Could not find any algorithm named \"" + name + "\"");
- }
-
-/*
-* Constructor for Invalid_Algorithm_Name
-*/
-Invalid_Algorithm_Name::Invalid_Algorithm_Name(const std::string& name)
- {
- set_msg("Invalid algorithm name: " + name);
- }
-
-/*
-* Constructor for Config_Error
-*/
-Config_Error::Config_Error(const std::string& err, u32bit line)
- {
- set_msg("Config error at line " + to_string(line) + ": " + err);
- }
-
-}
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)
+ {}
};
}
diff --git a/src/utils/info.txt b/src/utils/info.txt
index c797e1a0a..9d8f7976e 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -6,7 +6,6 @@ load_on always
charset.cpp
cpuid.cpp
debug.cpp
-exceptn.cpp
mlock.cpp
parsing.cpp
time.cpp