Botan  1.11.26
exceptn.h
Go to the documentation of this file.
1 /*
2 * Exceptions
3 * (C) 1999-2009 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
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 <string>
15 
16 namespace Botan {
17 
18 /**
19 * Base class for all exceptions thrown by the library
20 */
21 class BOTAN_DLL Exception : public std::exception
22  {
23  public:
24  Exception(const std::string& what) : m_what(what) {}
25  Exception(const char* prefix, const std::string& what) : m_what(std::string(prefix) + " " + what) {}
26  //const char* what() const override BOTAN_NOEXCEPT { return m_what.c_str(); }
27  const char* what() const BOTAN_NOEXCEPT override { return m_what.c_str(); }
28  private:
29  std::string m_what;
30  };
31 
32 /**
33 * An invalid argument which caused
34 */
35 class BOTAN_DLL Invalid_Argument : public Exception
36  {
37  public:
38  Invalid_Argument(const std::string& what) :
39  Exception("Invalid argument", what) {}
40  };
41 
42 /**
43 * Unsupported_Argument Exception
44 *
45 * An argument that is invalid because it is not supported by Botan.
46 * It might or might not be valid in another context like a standard.
47 */
48 struct BOTAN_DLL Unsupported_Argument : public Invalid_Argument
49  {
50  Unsupported_Argument(const std::string& msg) : Invalid_Argument(msg) {}
51  };
52 
53 /**
54 * Invalid_State Exception
55 */
56 struct BOTAN_DLL Invalid_State : public Exception
57  {
58  Invalid_State(const std::string& err) :
59  Exception(err)
60  {}
61  };
62 
63 /**
64 * Lookup_Error Exception
65 */
66 struct BOTAN_DLL Lookup_Error : public Exception
67  {
68  Lookup_Error(const std::string& err) :
69  Exception(err)
70  {}
71  };
72 
73 /**
74 * Internal_Error Exception
75 */
76 struct BOTAN_DLL Internal_Error : public Exception
77  {
78  Internal_Error(const std::string& err) :
79  Exception("Internal error: " + err)
80  {}
81  };
82 
83 /**
84 * Invalid_Key_Length Exception
85 */
86 struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument
87  {
88  Invalid_Key_Length(const std::string& name, size_t length) :
89  Invalid_Argument(name + " cannot accept a key of length " +
90  std::to_string(length))
91  {}
92  };
93 
94 /**
95 * Invalid_IV_Length Exception
96 */
97 struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument
98  {
99  Invalid_IV_Length(const std::string& mode, size_t bad_len) :
100  Invalid_Argument("IV length " + std::to_string(bad_len) +
101  " is invalid for " + mode)
102  {}
103  };
104 
105 /**
106 * PRNG_Unseeded Exception
107 */
108 struct BOTAN_DLL PRNG_Unseeded : public Invalid_State
109  {
110  PRNG_Unseeded(const std::string& algo) :
111  Invalid_State("PRNG not seeded: " + algo)
112  {}
113  };
114 
115 /**
116 * Policy_Violation Exception
117 */
118 struct BOTAN_DLL Policy_Violation : public Invalid_State
119  {
120  Policy_Violation(const std::string& err) :
121  Invalid_State("Policy violation: " + err)
122  {}
123  };
124 
125 /**
126 * Algorithm_Not_Found Exception
127 */
128 struct BOTAN_DLL Algorithm_Not_Found : public Lookup_Error
129  {
130  Algorithm_Not_Found(const std::string& name) :
131  Lookup_Error("Could not find any algorithm named \"" + name + "\"")
132  {}
133  };
134 
135 /**
136 * No_Provider_Found Exception
137 */
138 struct BOTAN_DLL No_Provider_Found : public Exception
139  {
140  No_Provider_Found(const std::string& name) :
141  Exception("Could not find any provider for algorithm named \"" + name + "\"")
142  {}
143  };
144 
145 /**
146 * Invalid_Algorithm_Name Exception
147 */
148 struct BOTAN_DLL Invalid_Algorithm_Name : public Invalid_Argument
149  {
150  Invalid_Algorithm_Name(const std::string& name):
151  Invalid_Argument("Invalid algorithm name: " + name)
152  {}
153  };
154 
155 /**
156 * Encoding_Error Exception
157 */
158 struct BOTAN_DLL Encoding_Error : public Invalid_Argument
159  {
160  Encoding_Error(const std::string& name) :
161  Invalid_Argument("Encoding error: " + name) {}
162  };
163 
164 /**
165 * Decoding_Error Exception
166 */
167 struct BOTAN_DLL Decoding_Error : public Invalid_Argument
168  {
169  Decoding_Error(const std::string& name) :
170  Invalid_Argument("Decoding error: " + name) {}
171  };
172 
173 /**
174 * Integrity_Failure Exception
175 */
176 struct BOTAN_DLL Integrity_Failure : public Exception
177  {
178  Integrity_Failure(const std::string& msg) :
179  Exception("Integrity failure: " + msg) {}
180  };
181 
182 /**
183 * Invalid_OID Exception
184 */
185 struct BOTAN_DLL Invalid_OID : public Decoding_Error
186  {
187  Invalid_OID(const std::string& oid) :
188  Decoding_Error("Invalid ASN.1 OID: " + oid) {}
189  };
190 
191 /**
192 * Stream_IO_Error Exception
193 */
194 struct BOTAN_DLL Stream_IO_Error : public Exception
195  {
196  Stream_IO_Error(const std::string& err) :
197  Exception("I/O error: " + err)
198  {}
199  };
200 
201 /**
202 * No_Filesystem_Access Exception
203 */
204 struct BOTAN_DLL No_Filesystem_Access : public Exception
205  {
206  No_Filesystem_Access() : Exception("No filesystem access enabled.") {}
207  };
208 
209 /**
210 * Self Test Failure Exception
211 */
212 struct BOTAN_DLL Self_Test_Failure : public Internal_Error
213  {
214  Self_Test_Failure(const std::string& err) :
215  Internal_Error("Self test failed: " + err)
216  {}
217  };
218 
219 }
220 
221 #endif
Invalid_IV_Length(const std::string &mode, size_t bad_len)
Definition: exceptn.h:99
std::string to_string(const secure_vector< byte > &bytes)
Definition: stl_util.h:25
Invalid_Key_Length(const std::string &name, size_t length)
Definition: exceptn.h:88
Algorithm_Not_Found(const std::string &name)
Definition: exceptn.h:130
PRNG_Unseeded(const std::string &algo)
Definition: exceptn.h:110
Stream_IO_Error(const std::string &err)
Definition: exceptn.h:196
Definition: bigint.h:610
No_Provider_Found(const std::string &name)
Definition: exceptn.h:140
Internal_Error(const std::string &err)
Definition: exceptn.h:78
Integrity_Failure(const std::string &msg)
Definition: exceptn.h:178
Decoding_Error(const std::string &name)
Definition: exceptn.h:169
Unsupported_Argument(const std::string &msg)
Definition: exceptn.h:50
Exception(const char *prefix, const std::string &what)
Definition: exceptn.h:25
Invalid_Algorithm_Name(const std::string &name)
Definition: exceptn.h:150
Self_Test_Failure(const std::string &err)
Definition: exceptn.h:214
Exception(const std::string &what)
Definition: exceptn.h:24
const char * what() const BOTAN_NOEXCEPT override
Definition: exceptn.h:27
Definition: alg_id.cpp:13
Invalid_State(const std::string &err)
Definition: exceptn.h:58
Invalid_Argument(const std::string &what)
Definition: exceptn.h:38
Lookup_Error(const std::string &err)
Definition: exceptn.h:68
Policy_Violation(const std::string &err)
Definition: exceptn.h:120
Encoding_Error(const std::string &name)
Definition: exceptn.h:160
OID oid
Definition: x509_ext.cpp:448
Invalid_OID(const std::string &oid)
Definition: exceptn.h:187