1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
/*
* Exceptions
* (C) 1999-2009 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_EXCEPTION_H__
#define BOTAN_EXCEPTION_H__
#include <botan/types.h>
#include <botan/parsing.h>
#include <exception>
#include <string>
namespace Botan {
/**
* Base class for all exceptions thrown by the library
*/
class BOTAN_PUBLIC_API(2,0) Exception : public std::exception
{
public:
explicit Exception(const std::string& msg) : m_msg(msg) {}
Exception(const char* prefix, const std::string& msg) : m_msg(std::string(prefix) + " " + msg) {}
const char* what() const BOTAN_NOEXCEPT override { return m_msg.c_str(); }
private:
std::string m_msg;
};
/**
* An invalid argument
*/
class BOTAN_PUBLIC_API(2,0) Invalid_Argument : public Exception
{
public:
explicit Invalid_Argument(const std::string& msg) :
Exception("Invalid argument", msg) {}
explicit Invalid_Argument(const std::string& msg, const std::string& where) :
Exception("Invalid argument", msg + " in " + where) {}
};
#define BOTAN_ARG_CHECK(expr) \
do { if(!(expr)) throw Invalid_Argument(#expr, BOTAN_CURRENT_FUNCTION); } while(0)
/**
* Unsupported_Argument Exception
*
* An argument that is invalid because it is not supported by Botan.
* It might or might not be valid in another context like a standard.
*/
struct BOTAN_PUBLIC_API(2,0) Unsupported_Argument : public Invalid_Argument
{
explicit Unsupported_Argument(const std::string& msg) : Invalid_Argument(msg) {}
};
/**
* Invalid_State Exception
*/
struct BOTAN_PUBLIC_API(2,0) Invalid_State : public Exception
{
explicit Invalid_State(const std::string& err) :
Exception(err)
{}
};
/**
* Lookup_Error Exception
*/
struct BOTAN_PUBLIC_API(2,0) Lookup_Error : public Exception
{
explicit Lookup_Error(const std::string& err) :
Exception(err)
{}
Lookup_Error(const std::string& type,
const std::string& algo,
const std::string& provider) :
Exception("Unavailable " + type + " " + algo +
(provider.empty() ? std::string("") : (" for provider " + provider)))
{}
};
/**
* Internal_Error Exception
*/
struct BOTAN_PUBLIC_API(2,0) Internal_Error : public Exception
{
explicit Internal_Error(const std::string& err) :
Exception("Internal error: " + err)
{}
};
/**
* Invalid_Key_Length Exception
*/
struct BOTAN_PUBLIC_API(2,0) Invalid_Key_Length : public Invalid_Argument
{
Invalid_Key_Length(const std::string& name, size_t length) :
Invalid_Argument(name + " cannot accept a key of length " +
std::to_string(length))
{}
};
/**
* Invalid_IV_Length Exception
*/
struct BOTAN_PUBLIC_API(2,0) Invalid_IV_Length : public Invalid_Argument
{
Invalid_IV_Length(const std::string& mode, size_t bad_len) :
Invalid_Argument("IV length " + std::to_string(bad_len) +
" is invalid for " + mode)
{}
};
/**
* PRNG_Unseeded Exception
*/
struct BOTAN_PUBLIC_API(2,0) PRNG_Unseeded : public Invalid_State
{
explicit PRNG_Unseeded(const std::string& algo) :
Invalid_State("PRNG not seeded: " + algo)
{}
};
/**
* Policy_Violation Exception
*/
struct BOTAN_PUBLIC_API(2,0) Policy_Violation : public Invalid_State
{
explicit Policy_Violation(const std::string& err) :
Invalid_State("Policy violation: " + err)
{}
};
/**
* Algorithm_Not_Found Exception
*/
struct BOTAN_PUBLIC_API(2,0) Algorithm_Not_Found : public Lookup_Error
{
explicit Algorithm_Not_Found(const std::string& name) :
Lookup_Error("Could not find any algorithm named \"" + name + "\"")
{}
};
/**
* No_Provider_Found Exception
*/
struct BOTAN_PUBLIC_API(2,0) No_Provider_Found : public Exception
{
explicit No_Provider_Found(const std::string& name) :
Exception("Could not find any provider for algorithm named \"" + name + "\"")
{}
};
/**
* Provider_Not_Found is thrown when a specific provider was requested
* but that provider is not available.
*/
struct BOTAN_PUBLIC_API(2,0) Provider_Not_Found : public Lookup_Error
{
Provider_Not_Found(const std::string& algo, const std::string& provider) :
Lookup_Error("Could not find provider '" + provider + "' for " + algo) {}
};
/**
* Invalid_Algorithm_Name Exception
*/
struct BOTAN_PUBLIC_API(2,0) Invalid_Algorithm_Name : public Invalid_Argument
{
explicit Invalid_Algorithm_Name(const std::string& name):
Invalid_Argument("Invalid algorithm name: " + name)
{}
};
/**
* Encoding_Error Exception
*/
struct BOTAN_PUBLIC_API(2,0) Encoding_Error : public Invalid_Argument
{
explicit Encoding_Error(const std::string& name) :
Invalid_Argument("Encoding error: " + name) {}
};
/**
* Decoding_Error Exception
*/
struct BOTAN_PUBLIC_API(2,0) Decoding_Error : public Invalid_Argument
{
explicit Decoding_Error(const std::string& name) :
Invalid_Argument("Decoding error: " + name) {}
};
/**
* Integrity_Failure Exception
*/
struct BOTAN_PUBLIC_API(2,0) Integrity_Failure : public Exception
{
explicit Integrity_Failure(const std::string& msg) :
Exception("Integrity failure: " + msg) {}
};
/**
* Invalid_OID Exception
*/
struct BOTAN_PUBLIC_API(2,0) Invalid_OID : public Decoding_Error
{
explicit Invalid_OID(const std::string& oid) :
Decoding_Error("Invalid ASN.1 OID: " + oid) {}
};
/**
* Stream_IO_Error Exception
*/
struct BOTAN_PUBLIC_API(2,0) Stream_IO_Error : public Exception
{
explicit Stream_IO_Error(const std::string& err) :
Exception("I/O error: " + err)
{}
};
/**
* No_Filesystem_Access Exception
*/
struct BOTAN_PUBLIC_API(2,0) No_Filesystem_Access : public Exception
{
No_Filesystem_Access() : Exception("No filesystem access enabled.") {}
};
/**
* Self Test Failure Exception
*/
struct BOTAN_PUBLIC_API(2,0) Self_Test_Failure : public Internal_Error
{
explicit Self_Test_Failure(const std::string& err) :
Internal_Error("Self test failed: " + err)
{}
};
/**
* Not Implemented Exception
*/
struct BOTAN_PUBLIC_API(2,0) Not_Implemented : public Exception
{
explicit Not_Implemented(const std::string& err) :
Exception("Not implemented", err)
{}
};
}
#endif
|