Botan  1.10.10
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 <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  std::to_string(length))
60  {}
61  };
62 
63 /**
64 * Invalid_IV_Length Exception
65 */
66 struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument
67  {
68  Invalid_IV_Length(const std::string& mode, size_t bad_len) :
69  Invalid_Argument("IV length " + std::to_string(bad_len) +
70  " is invalid for " + mode)
71  {}
72  };
73 
74 /**
75 * PRNG_Unseeded Exception
76 */
77 struct BOTAN_DLL PRNG_Unseeded : public Invalid_State
78  {
79  PRNG_Unseeded(const std::string& algo) :
80  Invalid_State("PRNG not seeded: " + algo)
81  {}
82  };
83 
84 /**
85 * Policy_Violation Exception
86 */
87 struct BOTAN_DLL Policy_Violation : public Invalid_State
88  {
89  Policy_Violation(const std::string& err) :
90  Invalid_State("Policy violation: " + err)
91  {}
92  };
93 
94 /**
95 * Algorithm_Not_Found Exception
96 */
97 struct BOTAN_DLL Algorithm_Not_Found : public Lookup_Error
98  {
99  Algorithm_Not_Found(const std::string& name) :
100  Lookup_Error("Could not find any algorithm named \"" + name + "\"")
101  {}
102  };
103 
104 /**
105 * Invalid_Algorithm_Name Exception
106 */
107 struct BOTAN_DLL Invalid_Algorithm_Name : public Invalid_Argument
108  {
109  Invalid_Algorithm_Name(const std::string& name):
110  Invalid_Argument("Invalid algorithm name: " + name)
111  {}
112  };
113 
114 /**
115 * Encoding_Error Exception
116 */
117 struct BOTAN_DLL Encoding_Error : public Invalid_Argument
118  {
119  Encoding_Error(const std::string& name) :
120  Invalid_Argument("Encoding error: " + name) {}
121  };
122 
123 /**
124 * Decoding_Error Exception
125 */
126 struct BOTAN_DLL Decoding_Error : public Invalid_Argument
127  {
128  Decoding_Error(const std::string& name) :
129  Invalid_Argument("Decoding error: " + name) {}
130  };
131 
132 /**
133 * Integrity_Failure Exception
134 */
135 struct BOTAN_DLL Integrity_Failure : public Exception
136  {
137  Integrity_Failure(const std::string& msg) :
138  Exception("Integrity failure: " + msg) {}
139  };
140 
141 /**
142 * Invalid_OID Exception
143 */
144 struct BOTAN_DLL Invalid_OID : public Decoding_Error
145  {
146  Invalid_OID(const std::string& oid) :
147  Decoding_Error("Invalid ASN.1 OID: " + oid) {}
148  };
149 
150 /**
151 * Stream_IO_Error Exception
152 */
153 struct BOTAN_DLL Stream_IO_Error : public Exception
154  {
155  Stream_IO_Error(const std::string& err) :
156  Exception("I/O error: " + err)
157  {}
158  };
159 
160 /**
161 * No_Filesystem_Access Exception
162 */
163 struct BOTAN_DLL No_Filesystem_Access : public Exception
164  {
165  No_Filesystem_Access() : Exception("No filesystem access enabled.") {}
166  };
167 
168 /**
169 * Self Test Failure Exception
170 */
171 struct BOTAN_DLL Self_Test_Failure : public Internal_Error
172  {
173  Self_Test_Failure(const std::string& err) :
174  Internal_Error("Self test failed: " + err)
175  {}
176  };
177 
178 /**
179 * Memory Allocation Exception
180 */
181 struct BOTAN_DLL Memory_Exhaustion : public std::bad_alloc
182  {
183  const char* what() const BOTAN_NOEXCEPT override
184  { return "Ran out of memory, allocation failed"; }
185  };
186 
187 }
188 
189 #endif
Invalid_IV_Length(const std::string &mode, size_t bad_len)
Definition: exceptn.h:68
std::string to_string(const secure_vector< byte > &bytes)
Definition: stl_util.h:24
Invalid_Key_Length(const std::string &name, size_t length)
Definition: exceptn.h:57
Algorithm_Not_Found(const std::string &name)
Definition: exceptn.h:99
PRNG_Unseeded(const std::string &algo)
Definition: exceptn.h:79
Stream_IO_Error(const std::string &err)
Definition: exceptn.h:155
Definition: bigint.h:610
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:137
Decoding_Error(const std::string &name)
Definition: exceptn.h:128
Invalid_Algorithm_Name(const std::string &name)
Definition: exceptn.h:109
Self_Test_Failure(const std::string &err)
Definition: exceptn.h:173
std::runtime_error Exception
Definition: exceptn.h:19
const char * what() const BOTAN_NOEXCEPT override
Definition: exceptn.h:183
Invalid_State(const std::string &err)
Definition: exceptn.h:27
Lookup_Error(const std::string &err)
Definition: exceptn.h:37
Policy_Violation(const std::string &err)
Definition: exceptn.h:89
Encoding_Error(const std::string &name)
Definition: exceptn.h:119
OID oid
Definition: x509_ext.cpp:447
Invalid_OID(const std::string &oid)
Definition: exceptn.h:146