Botan  2.11.0
Crypto and TLS for C++11
exceptn.cpp
Go to the documentation of this file.
1 /*
2 * (C) 2017 Jack Lloyd
3 *
4 * Botan is released under the Simplified BSD License (see license.txt)
5 */
6 
7 #include <botan/exceptn.h>
8 
9 namespace Botan {
10 
11 std::string to_string(ErrorType type)
12  {
13  switch(type)
14  {
15  case ErrorType::Unknown:
16  return "Unknown";
18  return "SystemError";
20  return "NotImplemented";
22  return "OutOfMemory";
24  return "InternalError";
25  case ErrorType::IoError:
26  return "IoError";
28  return "InvalidObjectState";
30  return "KeyNotSet";
32  return "InvalidArgument";
34  return "InvalidKeyLength";
36  return "InvalidNonceLength";
38  return "LookupError";
40  return "EncodingFailure";
42  return "DecodingFailure";
44  return "TLSError";
46  return "HttpError";
48  return "InvalidTag";
50  return "OpenSSLError";
52  return "CommonCryptoError";
54  return "Pkcs11Error";
56  return "TPMError";
58  return "DatabaseError";
60  return "ZlibError";
62  return "Bzip2Error" ;
64  return "LzmaError";
65  }
66 
67  // No default case in above switch so compiler warns
68  return "Unrecognized Botan error";
69  }
70 
71 Exception::Exception(const std::string& msg) : m_msg(msg)
72  {}
73 
74 Exception::Exception(const std::string& msg, const std::exception& e) :
75  m_msg(msg + " failed with " + std::string(e.what()))
76  {}
77 
78 Exception::Exception(const char* prefix, const std::string& msg) :
79  m_msg(std::string(prefix) + " " + msg)
80  {}
81 
82 Invalid_Argument::Invalid_Argument(const std::string& msg) :
83  Exception(msg)
84  {}
85 
86 Invalid_Argument::Invalid_Argument(const std::string& msg, const std::string& where) :
87  Exception(msg + " in " + where)
88  {}
89 
90 Invalid_Argument::Invalid_Argument(const std::string& msg, const std::exception& e) :
91  Exception(msg, e) {}
92 
93 Lookup_Error::Lookup_Error(const std::string& type,
94  const std::string& algo,
95  const std::string& provider) :
96  Exception("Unavailable " + type + " " + algo +
97  (provider.empty() ? std::string("") : (" for provider " + provider)))
98  {}
99 
100 Internal_Error::Internal_Error(const std::string& err) :
101  Exception("Internal error: " + err)
102  {}
103 
104 Invalid_Key_Length::Invalid_Key_Length(const std::string& name, size_t length) :
105  Invalid_Argument(name + " cannot accept a key of length " +
106  std::to_string(length))
107  {}
108 
109 Invalid_IV_Length::Invalid_IV_Length(const std::string& mode, size_t bad_len) :
110  Invalid_Argument("IV length " + std::to_string(bad_len) +
111  " is invalid for " + mode)
112  {}
113 
114 Key_Not_Set::Key_Not_Set(const std::string& algo) :
115  Invalid_State("Key not set in " + algo)
116  {}
117 
118 Policy_Violation::Policy_Violation(const std::string& err) :
119  Invalid_State("Policy violation: " + err) {}
120 
121 PRNG_Unseeded::PRNG_Unseeded(const std::string& algo) :
122  Invalid_State("PRNG not seeded: " + algo)
123  {}
124 
126  Lookup_Error("Could not find any algorithm named \"" + name + "\"")
127  {}
128 
130  Exception("Could not find any provider for algorithm named \"" + name + "\"")
131  {}
132 
133 Provider_Not_Found::Provider_Not_Found(const std::string& algo, const std::string& provider) :
134  Lookup_Error("Could not find provider '" + provider + "' for " + algo)
135  {}
136 
138  Invalid_Argument("Invalid algorithm name: " + name)
139  {}
140 
142  Invalid_Argument("Encoding error: " + name)
143  {}
144 
147  {}
148 
149 Decoding_Error::Decoding_Error(const std::string& msg, const std::exception& e) :
150  Invalid_Argument(msg, e)
151  {}
152 
153 Decoding_Error::Decoding_Error(const std::string& name, const char* exception_message) :
154  Invalid_Argument(name + " failed with exception " + exception_message) {}
155 
157  Exception("Invalid authentication tag: " + msg)
158  {}
159 
160 Invalid_OID::Invalid_OID(const std::string& oid) :
161  Decoding_Error("Invalid ASN.1 OID: " + oid)
162  {}
163 
164 Stream_IO_Error::Stream_IO_Error(const std::string& err) :
165  Exception("I/O error: " + err)
166  {}
167 
168 System_Error::System_Error(const std::string& msg, int err_code) :
169  Exception(msg + " error code " + std::to_string(err_code)),
170  m_error_code(err_code)
171  {}
172 
173 Self_Test_Failure::Self_Test_Failure(const std::string& err) :
174  Internal_Error("Self test failed: " + err)
175  {}
176 
177 Not_Implemented::Not_Implemented(const std::string& err) :
178  Exception("Not implemented", err)
179  {}
180 
181 }
Encoding_Error(const std::string &name)
Definition: exceptn.cpp:141
Invalid_Algorithm_Name(const std::string &name)
Definition: exceptn.cpp:137
Exception(const std::string &msg)
Definition: exceptn.cpp:71
Invalid_Argument(const std::string &msg)
Definition: exceptn.cpp:82
Definition: bigint.h:1136
Policy_Violation(const std::string &err)
Definition: exceptn.cpp:118
MechanismType type
Decoding_Error(const std::string &name)
Definition: exceptn.cpp:145
Key_Not_Set(const std::string &algo)
Definition: exceptn.cpp:114
Not_Implemented(const std::string &err)
Definition: exceptn.cpp:177
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition: exceptn.cpp:11
Provider_Not_Found(const std::string &algo, const std::string &provider)
Definition: exceptn.cpp:133
std::string name
Stream_IO_Error(const std::string &err)
Definition: exceptn.cpp:164
ErrorType
Definition: exceptn.h:20
Algorithm_Not_Found(const std::string &name)
Definition: exceptn.cpp:125
No_Provider_Found(const std::string &name)
Definition: exceptn.cpp:129
Definition: alg_id.cpp:13
PRNG_Unseeded(const std::string &algo)
Definition: exceptn.cpp:121
Invalid_OID(const std::string &oid)
Definition: exceptn.cpp:160
System_Error(const std::string &msg)
Definition: exceptn.h:324
Invalid_Authentication_Tag(const std::string &msg)
Definition: exceptn.cpp:156
Internal_Error(const std::string &err)
Definition: exceptn.cpp:100
Invalid_Key_Length(const std::string &name, size_t length)
Definition: exceptn.cpp:104
Invalid_IV_Length(const std::string &mode, size_t bad_len)
Definition: exceptn.cpp:109
Self_Test_Failure(const std::string &err)
Definition: exceptn.cpp:173
Lookup_Error(const std::string &err)
Definition: exceptn.h:248