Botan  1.10.9
exceptn.h
Go to the documentation of this file.
1 /*
2 * Exceptions
3 * (C) 1999-2009 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #ifndef BOTAN_EXCEPTION_H__
9 #define BOTAN_EXCEPTION_H__
10 
11 #include <botan/types.h>
12 #include <botan/parsing.h>
13 #include <exception>
14 #include <stdexcept>
15 #include <string>
16 
17 namespace Botan {
18 
19 typedef std::runtime_error Exception;
20 typedef std::invalid_argument Invalid_Argument;
21 
22 /**
23 * Invalid_State Exception
24 */
25 struct BOTAN_DLL Invalid_State : public Exception
26  {
27  Invalid_State(const std::string& err) :
28  Exception(err)
29  {}
30  };
31 
32 /**
33 * Lookup_Error Exception
34 */
35 struct BOTAN_DLL Lookup_Error : public Exception
36  {
37  Lookup_Error(const std::string& err) :
38  Exception(err)
39  {}
40  };
41 
42 /**
43 * Internal_Error Exception
44 */
45 struct BOTAN_DLL Internal_Error : public Exception
46  {
47  Internal_Error(const std::string& err) :
48  Exception("Internal error: " + err)
49  {}
50  };
51 
52 /**
53 * Invalid_Key_Length Exception
54 */
55 struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument
56  {
57  Invalid_Key_Length(const std::string& name, size_t length) :
58  Invalid_Argument(name + " cannot accept a key of length " +
59  to_string(length))
60  {}
61  };
62 
63 /**
64 * Invalid_Block_Size Exception
65 */
66 struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument
67  {
68  Invalid_Block_Size(const std::string& mode,
69  const std::string& pad) :
70  Invalid_Argument("Padding method " + pad +
71  " cannot be used with " + mode)
72  {}
73  };
74 
75 /**
76 * Invalid_IV_Length Exception
77 */
78 struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument
79  {
80  Invalid_IV_Length(const std::string& mode, size_t bad_len) :
81  Invalid_Argument("IV length " + to_string(bad_len) +
82  " is invalid for " + mode)
83  {}
84  };
85 
86 /**
87 * PRNG_Unseeded Exception
88 */
89 struct BOTAN_DLL PRNG_Unseeded : public Invalid_State
90  {
91  PRNG_Unseeded(const std::string& algo) :
92  Invalid_State("PRNG not seeded: " + algo)
93  {}
94  };
95 
96 /**
97 * Policy_Violation Exception
98 */
99 struct BOTAN_DLL Policy_Violation : public Invalid_State
100  {
101  Policy_Violation(const std::string& err) :
102  Invalid_State("Policy violation: " + err)
103  {}
104  };
105 
106 /**
107 * Algorithm_Not_Found Exception
108 */
109 struct BOTAN_DLL Algorithm_Not_Found : public Lookup_Error
110  {
111  Algorithm_Not_Found(const std::string& name) :
112  Lookup_Error("Could not find any algorithm named \"" + name + "\"")
113  {}
114  };
115 
116 /**
117 * Invalid_Algorithm_Name Exception
118 */
119 struct BOTAN_DLL Invalid_Algorithm_Name : public Invalid_Argument
120  {
121  Invalid_Algorithm_Name(const std::string& name):
122  Invalid_Argument("Invalid algorithm name: " + name)
123  {}
124  };
125 
126 /**
127 * Encoding_Error Exception
128 */
129 struct BOTAN_DLL Encoding_Error : public Invalid_Argument
130  {
131  Encoding_Error(const std::string& name) :
132  Invalid_Argument("Encoding error: " + name) {}
133  };
134 
135 /**
136 * Decoding_Error Exception
137 */
138 struct BOTAN_DLL Decoding_Error : public Invalid_Argument
139  {
140  Decoding_Error(const std::string& name) :
141  Invalid_Argument("Decoding error: " + name) {}
142  };
143 
144 /**
145 * Integrity_Failure Exception
146 */
147 struct BOTAN_DLL Integrity_Failure : public Exception
148  {
149  Integrity_Failure(const std::string& msg) :
150  Exception("Integrity failure: " + msg) {}
151  };
152 
153 /**
154 * Invalid_OID Exception
155 */
156 struct BOTAN_DLL Invalid_OID : public Decoding_Error
157  {
158  Invalid_OID(const std::string& oid) :
159  Decoding_Error("Invalid ASN.1 OID: " + oid) {}
160  };
161 
162 /**
163 * Stream_IO_Error Exception
164 */
165 struct BOTAN_DLL Stream_IO_Error : public Exception
166  {
167  Stream_IO_Error(const std::string& err) :
168  Exception("I/O error: " + err)
169  {}
170  };
171 
172 /**
173 * Self Test Failure Exception
174 */
175 struct BOTAN_DLL Self_Test_Failure : public Internal_Error
176  {
177  Self_Test_Failure(const std::string& err) :
178  Internal_Error("Self test failed: " + err)
179  {}
180  };
181 
182 /**
183 * Memory Allocation Exception
184 */
185 struct BOTAN_DLL Memory_Exhaustion : public std::bad_alloc
186  {
187  const char* what() const throw()
188  { return "Ran out of memory, allocation failed"; }
189  };
190 
191 }
192 
193 #endif
Invalid_IV_Length(const std::string &mode, size_t bad_len)
Definition: exceptn.h:80
Invalid_Block_Size(const std::string &mode, const std::string &pad)
Definition: exceptn.h:68
Invalid_Key_Length(const std::string &name, size_t length)
Definition: exceptn.h:57
const char * what() const
Definition: exceptn.h:187
Algorithm_Not_Found(const std::string &name)
Definition: exceptn.h:111
PRNG_Unseeded(const std::string &algo)
Definition: exceptn.h:91
Stream_IO_Error(const std::string &err)
Definition: exceptn.h:167
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Internal_Error(const std::string &err)
Definition: exceptn.h:47
Integrity_Failure(const std::string &msg)
Definition: exceptn.h:149
Decoding_Error(const std::string &name)
Definition: exceptn.h:140
Invalid_Algorithm_Name(const std::string &name)
Definition: exceptn.h:121
Self_Test_Failure(const std::string &err)
Definition: exceptn.h:177
std::runtime_error Exception
Definition: exceptn.h:19
Invalid_State(const std::string &err)
Definition: exceptn.h:27
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42
Lookup_Error(const std::string &err)
Definition: exceptn.h:37
Policy_Violation(const std::string &err)
Definition: exceptn.h:101
Encoding_Error(const std::string &name)
Definition: exceptn.h:131
OID oid
Definition: x509_ext.cpp:446
Invalid_OID(const std::string &oid)
Definition: exceptn.h:158