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