/src/botan/src/lib/utils/exceptn.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 0 | { |
13 | 0 | switch(type) |
14 | 0 | { |
15 | 0 | case ErrorType::Unknown: |
16 | 0 | return "Unknown"; |
17 | 0 | case ErrorType::SystemError: |
18 | 0 | return "SystemError"; |
19 | 0 | case ErrorType::NotImplemented: |
20 | 0 | return "NotImplemented"; |
21 | 0 | case ErrorType::OutOfMemory: |
22 | 0 | return "OutOfMemory"; |
23 | 0 | case ErrorType::InternalError: |
24 | 0 | return "InternalError"; |
25 | 0 | case ErrorType::IoError: |
26 | 0 | return "IoError"; |
27 | 0 | case ErrorType::InvalidObjectState : |
28 | 0 | return "InvalidObjectState"; |
29 | 0 | case ErrorType::KeyNotSet: |
30 | 0 | return "KeyNotSet"; |
31 | 0 | case ErrorType::InvalidArgument: |
32 | 0 | return "InvalidArgument"; |
33 | 0 | case ErrorType::InvalidKeyLength: |
34 | 0 | return "InvalidKeyLength"; |
35 | 0 | case ErrorType::InvalidNonceLength: |
36 | 0 | return "InvalidNonceLength"; |
37 | 0 | case ErrorType::LookupError: |
38 | 0 | return "LookupError"; |
39 | 0 | case ErrorType::EncodingFailure: |
40 | 0 | return "EncodingFailure"; |
41 | 0 | case ErrorType::DecodingFailure: |
42 | 0 | return "DecodingFailure"; |
43 | 0 | case ErrorType::TLSError: |
44 | 0 | return "TLSError"; |
45 | 0 | case ErrorType::HttpError: |
46 | 0 | return "HttpError"; |
47 | 0 | case ErrorType::InvalidTag: |
48 | 0 | return "InvalidTag"; |
49 | 0 | case ErrorType::RoughtimeError: |
50 | 0 | return "RoughtimeError"; |
51 | 0 | case ErrorType::OpenSSLError : |
52 | 0 | return "OpenSSLError"; |
53 | 0 | case ErrorType::CommonCryptoError: |
54 | 0 | return "CommonCryptoError"; |
55 | 0 | case ErrorType::Pkcs11Error: |
56 | 0 | return "Pkcs11Error"; |
57 | 0 | case ErrorType::TPMError: |
58 | 0 | return "TPMError"; |
59 | 0 | case ErrorType::DatabaseError: |
60 | 0 | return "DatabaseError"; |
61 | 0 | case ErrorType::ZlibError : |
62 | 0 | return "ZlibError"; |
63 | 0 | case ErrorType::Bzip2Error: |
64 | 0 | return "Bzip2Error" ; |
65 | 0 | case ErrorType::LzmaError: |
66 | 0 | return "LzmaError"; |
67 | 0 | } |
68 | | |
69 | | // No default case in above switch so compiler warns |
70 | 0 | return "Unrecognized Botan error"; |
71 | 0 | } |
72 | | |
73 | | Exception::Exception(const std::string& msg) : m_msg(msg) |
74 | 87.0k | {} |
75 | | |
76 | | Exception::Exception(const std::string& msg, const std::exception& e) : |
77 | | m_msg(msg + " failed with " + std::string(e.what())) |
78 | 11.1k | {} |
79 | | |
80 | | Exception::Exception(const char* prefix, const std::string& msg) : |
81 | | m_msg(std::string(prefix) + " " + msg) |
82 | 0 | {} |
83 | | |
84 | | Invalid_Argument::Invalid_Argument(const std::string& msg) : |
85 | | Exception(msg) |
86 | 11.5k | {} |
87 | | |
88 | | Invalid_Argument::Invalid_Argument(const std::string& msg, const std::string& where) : |
89 | | Exception(msg + " in " + where) |
90 | 0 | {} |
91 | | |
92 | | Invalid_Argument::Invalid_Argument(const std::string& msg, const std::exception& e) : |
93 | 0 | Exception(msg, e) {} |
94 | | |
95 | | Lookup_Error::Lookup_Error(const std::string& type, |
96 | | const std::string& algo, |
97 | | const std::string& provider) : |
98 | | Exception("Unavailable " + type + " " + algo + |
99 | | (provider.empty() ? std::string("") : (" for provider " + provider))) |
100 | 0 | {} |
101 | | |
102 | | Internal_Error::Internal_Error(const std::string& err) : |
103 | | Exception("Internal error: " + err) |
104 | 1.04k | {} |
105 | | |
106 | | Invalid_Key_Length::Invalid_Key_Length(const std::string& name, size_t length) : |
107 | | Invalid_Argument(name + " cannot accept a key of length " + |
108 | | std::to_string(length)) |
109 | 0 | {} |
110 | | |
111 | | Invalid_IV_Length::Invalid_IV_Length(const std::string& mode, size_t bad_len) : |
112 | | Invalid_Argument("IV length " + std::to_string(bad_len) + |
113 | | " is invalid for " + mode) |
114 | 0 | {} |
115 | | |
116 | | Key_Not_Set::Key_Not_Set(const std::string& algo) : |
117 | | Invalid_State("Key not set in " + algo) |
118 | 0 | {} |
119 | | |
120 | | PRNG_Unseeded::PRNG_Unseeded(const std::string& algo) : |
121 | | Invalid_State("PRNG not seeded: " + algo) |
122 | 0 | {} |
123 | | |
124 | | Algorithm_Not_Found::Algorithm_Not_Found(const std::string& name) : |
125 | | Lookup_Error("Could not find any algorithm named \"" + name + "\"") |
126 | 0 | {} |
127 | | |
128 | | Provider_Not_Found::Provider_Not_Found(const std::string& algo, const std::string& provider) : |
129 | | Lookup_Error("Could not find provider '" + provider + "' for " + algo) |
130 | 0 | {} |
131 | | |
132 | | Invalid_Algorithm_Name::Invalid_Algorithm_Name(const std::string& name): |
133 | | Invalid_Argument("Invalid algorithm name: " + name) |
134 | 0 | {} |
135 | | |
136 | | Encoding_Error::Encoding_Error(const std::string& name) : |
137 | | Exception("Encoding error: " + name) |
138 | 1.09k | {} |
139 | | |
140 | | Decoding_Error::Decoding_Error(const std::string& name) : |
141 | | Exception(name) |
142 | 68.2k | {} |
143 | | |
144 | | Decoding_Error::Decoding_Error(const std::string& msg, const std::exception& e) : |
145 | | Exception(msg, e) |
146 | 11.1k | {} |
147 | | |
148 | | Decoding_Error::Decoding_Error(const std::string& name, const char* exception_message) : |
149 | 0 | Exception(name + " failed with exception " + exception_message) {} |
150 | | |
151 | | Invalid_Authentication_Tag::Invalid_Authentication_Tag(const std::string& msg) : |
152 | | Exception("Invalid authentication tag: " + msg) |
153 | 256 | {} |
154 | | |
155 | | Stream_IO_Error::Stream_IO_Error(const std::string& err) : |
156 | | Exception("I/O error: " + err) |
157 | 189 | {} |
158 | | |
159 | | System_Error::System_Error(const std::string& msg, int err_code) : |
160 | | Exception(msg + " error code " + std::to_string(err_code)), |
161 | | m_error_code(err_code) |
162 | 0 | {} |
163 | | |
164 | | Not_Implemented::Not_Implemented(const std::string& err) : |
165 | | Exception("Not implemented", err) |
166 | 0 | {} |
167 | | |
168 | | } |