1 | /* |
2 | Copyright (C) 1999-2007 The Botan Project. All rights reserved. |
3 | |
4 | Redistribution and use in source and binary forms, for any use, with or without |
5 | modification, is permitted provided that the following conditions are met: |
6 | |
7 | 1. Redistributions of source code must retain the above copyright notice, this |
8 | list of conditions, and the following disclaimer. |
9 | |
10 | 2. Redistributions in binary form must reproduce the above copyright notice, |
11 | this list of conditions, and the following disclaimer in the documentation |
12 | and/or other materials provided with the distribution. |
13 | |
14 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED |
15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
16 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. |
17 | |
18 | IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT, |
19 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
20 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
22 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
23 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
24 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | */ |
26 | // LICENSEHEADER_END |
27 | namespace QCA { // WRAPNS_LINE |
28 | /************************************************* |
29 | * Exceptions Header File * |
30 | * (C) 1999-2007 The Botan Project * |
31 | *************************************************/ |
32 | |
33 | #ifndef BOTAN_EXCEPTION_H__ |
34 | #define BOTAN_EXCEPTION_H__ |
35 | |
36 | } // WRAPNS_LINE |
37 | #include <botan/types.h> |
38 | namespace QCA { // WRAPNS_LINE |
39 | } // WRAPNS_LINE |
40 | #include <exception> |
41 | namespace QCA { // WRAPNS_LINE |
42 | } // WRAPNS_LINE |
43 | #include <string> |
44 | namespace QCA { // WRAPNS_LINE |
45 | |
46 | namespace Botan { |
47 | |
48 | /************************************************* |
49 | * Exception Base Class * |
50 | *************************************************/ |
51 | class Exception : public std::exception |
52 | { |
53 | public: |
54 | const char *what() const throw() override |
55 | { |
56 | return msg.c_str(); |
57 | } |
58 | Exception(const std::string &m = "Unknown error" ) |
59 | { |
60 | set_msg(m); |
61 | } |
62 | ~Exception() throw() override |
63 | { |
64 | } |
65 | |
66 | protected: |
67 | void set_msg(const std::string &m) |
68 | { |
69 | msg = "Botan: " + m; |
70 | } |
71 | |
72 | private: |
73 | std::string msg; |
74 | }; |
75 | |
76 | /************************************************* |
77 | * Invalid_Argument Exception * |
78 | *************************************************/ |
79 | struct Invalid_Argument : public Exception |
80 | { |
81 | Invalid_Argument(const std::string &err = "" ) |
82 | : Exception(err) |
83 | { |
84 | } |
85 | }; |
86 | |
87 | /************************************************* |
88 | * Invalid_Key_Length Exception * |
89 | *************************************************/ |
90 | struct Invalid_Key_Length : public Invalid_Argument |
91 | { |
92 | Invalid_Key_Length(const std::string &, u32bit); |
93 | }; |
94 | |
95 | /************************************************* |
96 | * Invalid_Block_Size Exception * |
97 | *************************************************/ |
98 | struct Invalid_Block_Size : public Invalid_Argument |
99 | { |
100 | Invalid_Block_Size(const std::string &, const std::string &); |
101 | }; |
102 | |
103 | /************************************************* |
104 | * Invalid_IV_Length Exception * |
105 | *************************************************/ |
106 | struct Invalid_IV_Length : public Invalid_Argument |
107 | { |
108 | Invalid_IV_Length(const std::string &, u32bit); |
109 | }; |
110 | |
111 | /************************************************* |
112 | * Invalid_Message_Number Exception * |
113 | *************************************************/ |
114 | struct Invalid_Message_Number : public Invalid_Argument |
115 | { |
116 | Invalid_Message_Number(const std::string &, u32bit); |
117 | }; |
118 | |
119 | /************************************************* |
120 | * Invalid_State Exception * |
121 | *************************************************/ |
122 | struct Invalid_State : public Exception |
123 | { |
124 | Invalid_State(const std::string &err) |
125 | : Exception(err) |
126 | { |
127 | } |
128 | }; |
129 | |
130 | /************************************************* |
131 | * PRNG_Unseeded Exception * |
132 | *************************************************/ |
133 | struct PRNG_Unseeded : public Invalid_State |
134 | { |
135 | PRNG_Unseeded(const std::string &algo) |
136 | : Invalid_State("PRNG not seeded: " + algo) |
137 | { |
138 | } |
139 | }; |
140 | |
141 | /************************************************* |
142 | * Policy_Violation Exception * |
143 | *************************************************/ |
144 | struct Policy_Violation : public Invalid_State |
145 | { |
146 | Policy_Violation(const std::string &err) |
147 | : Invalid_State("Policy violation: " + err) |
148 | { |
149 | } |
150 | }; |
151 | |
152 | /************************************************* |
153 | * Lookup_Error Exception * |
154 | *************************************************/ |
155 | struct Lookup_Error : public Exception |
156 | { |
157 | Lookup_Error(const std::string &err) |
158 | : Exception(err) |
159 | { |
160 | } |
161 | }; |
162 | |
163 | /************************************************* |
164 | * Algorithm_Not_Found Exception * |
165 | *************************************************/ |
166 | struct Algorithm_Not_Found : public Exception |
167 | { |
168 | Algorithm_Not_Found(const std::string &); |
169 | }; |
170 | |
171 | /************************************************* |
172 | * Format_Error Exception * |
173 | *************************************************/ |
174 | struct Format_Error : public Exception |
175 | { |
176 | Format_Error(const std::string &err = "" ) |
177 | : Exception(err) |
178 | { |
179 | } |
180 | }; |
181 | |
182 | /************************************************* |
183 | * Invalid_Algorithm_Name Exception * |
184 | *************************************************/ |
185 | struct Invalid_Algorithm_Name : public Format_Error |
186 | { |
187 | Invalid_Algorithm_Name(const std::string &); |
188 | }; |
189 | |
190 | /************************************************* |
191 | * Encoding_Error Exception * |
192 | *************************************************/ |
193 | struct Encoding_Error : public Format_Error |
194 | { |
195 | Encoding_Error(const std::string &name) |
196 | : Format_Error("Encoding error: " + name) |
197 | { |
198 | } |
199 | }; |
200 | |
201 | /************************************************* |
202 | * Decoding_Error Exception * |
203 | *************************************************/ |
204 | struct Decoding_Error : public Format_Error |
205 | { |
206 | Decoding_Error(const std::string &name) |
207 | : Format_Error("Decoding error: " + name) |
208 | { |
209 | } |
210 | }; |
211 | |
212 | /************************************************* |
213 | * Invalid_OID Exception * |
214 | *************************************************/ |
215 | struct Invalid_OID : public Decoding_Error |
216 | { |
217 | Invalid_OID(const std::string &oid) |
218 | : Decoding_Error("Invalid ASN.1 OID: " + oid) |
219 | { |
220 | } |
221 | }; |
222 | |
223 | /************************************************* |
224 | * Stream_IO_Error Exception * |
225 | *************************************************/ |
226 | struct Stream_IO_Error : public Exception |
227 | { |
228 | Stream_IO_Error(const std::string &err) |
229 | : Exception("I/O error: " + err) |
230 | { |
231 | } |
232 | }; |
233 | |
234 | /************************************************* |
235 | * Configuration Error Exception * |
236 | *************************************************/ |
237 | struct Config_Error : public Format_Error |
238 | { |
239 | Config_Error(const std::string &err) |
240 | : Format_Error("Config error: " + err) |
241 | { |
242 | } |
243 | Config_Error(const std::string &, u32bit); |
244 | }; |
245 | |
246 | /************************************************* |
247 | * Integrity Failure Exception * |
248 | *************************************************/ |
249 | struct Integrity_Failure : public Exception |
250 | { |
251 | Integrity_Failure(const std::string &err) |
252 | : Exception("Integrity failure: " + err) |
253 | { |
254 | } |
255 | }; |
256 | |
257 | /************************************************* |
258 | * Internal_Error Exception * |
259 | *************************************************/ |
260 | struct Internal_Error : public Exception |
261 | { |
262 | Internal_Error(const std::string &err) |
263 | : Exception("Internal error: " + err) |
264 | { |
265 | } |
266 | }; |
267 | |
268 | /************************************************* |
269 | * Self Test Failure Exception * |
270 | *************************************************/ |
271 | struct Self_Test_Failure : public Internal_Error |
272 | { |
273 | Self_Test_Failure(const std::string &err) |
274 | : Internal_Error("Self test failed: " + err) |
275 | { |
276 | } |
277 | }; |
278 | |
279 | /************************************************* |
280 | * Memory Allocation Exception * |
281 | *************************************************/ |
282 | struct Memory_Exhaustion : public Exception |
283 | { |
284 | Memory_Exhaustion() |
285 | : Exception("Ran out of memory, allocation failed" ) |
286 | { |
287 | } |
288 | }; |
289 | |
290 | } |
291 | |
292 | #endif |
293 | } // WRAPNS_LINE |
294 | |