Coverage Report

Created: 2019-09-11 14:12

/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::OpenSSLError :
50
0
         return "OpenSSLError";
51
0
      case ErrorType::CommonCryptoError:
52
0
         return "CommonCryptoError";
53
0
      case ErrorType::Pkcs11Error:
54
0
         return "Pkcs11Error";
55
0
      case ErrorType::TPMError:
56
0
         return "TPMError";
57
0
      case ErrorType::DatabaseError:
58
0
         return "DatabaseError";
59
0
      case ErrorType::ZlibError :
60
0
         return "ZlibError";
61
0
      case ErrorType::Bzip2Error:
62
0
         return "Bzip2Error" ;
63
0
      case ErrorType::LzmaError:
64
0
         return "LzmaError";
65
0
      }
66
0
67
0
   // No default case in above switch so compiler warns
68
0
   return "Unrecognized Botan error";
69
0
   }
70
71
Exception::Exception(const std::string& msg) : m_msg(msg)
72
65.5k
   {}
73
74
Exception::Exception(const std::string& msg, const std::exception& e) :
75
   m_msg(msg + " failed with " + std::string(e.what()))
76
10.2k
   {}
77
78
Exception::Exception(const char* prefix, const std::string& msg) :
79
   m_msg(std::string(prefix) + " " + msg)
80
0
   {}
81
82
Invalid_Argument::Invalid_Argument(const std::string& msg) :
83
   Exception(msg)
84
58.6k
   {}
85
86
Invalid_Argument::Invalid_Argument(const std::string& msg, const std::string& where) :
87
   Exception(msg + " in " + where)
88
0
   {}
89
90
Invalid_Argument::Invalid_Argument(const std::string& msg, const std::exception& e) :
91
10.2k
   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
0
   {}
99
100
Internal_Error::Internal_Error(const std::string& err) :
101
   Exception("Internal error: " + err)
102
1.20k
   {}
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
0
   {}
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
0
   {}
113
114
Key_Not_Set::Key_Not_Set(const std::string& algo) :
115
   Invalid_State("Key not set in " + algo)
116
0
   {}
117
118
Policy_Violation::Policy_Violation(const std::string& err) :
119
0
   Invalid_State("Policy violation: " + err) {}
120
121
PRNG_Unseeded::PRNG_Unseeded(const std::string& algo) :
122
   Invalid_State("PRNG not seeded: " + algo)
123
0
   {}
124
125
Algorithm_Not_Found::Algorithm_Not_Found(const std::string& name) :
126
   Lookup_Error("Could not find any algorithm named \"" + name + "\"")
127
2
   {}
128
129
No_Provider_Found::No_Provider_Found(const std::string& name) :
130
   Exception("Could not find any provider for algorithm named \"" + name + "\"")
131
0
   {}
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
0
   {}
136
137
Invalid_Algorithm_Name::Invalid_Algorithm_Name(const std::string& name):
138
   Invalid_Argument("Invalid algorithm name: " + name)
139
0
   {}
140
141
Encoding_Error::Encoding_Error(const std::string& name) :
142
   Invalid_Argument("Encoding error: " + name)
143
257
   {}
144
145
Decoding_Error::Decoding_Error(const std::string& name) :
146
   Invalid_Argument(name)
147
48.0k
   {}
148
149
Decoding_Error::Decoding_Error(const std::string& msg, const std::exception& e) :
150
   Invalid_Argument(msg, e)
151
10.2k
   {}
152
153
Decoding_Error::Decoding_Error(const std::string& name, const char* exception_message) :
154
0
   Invalid_Argument(name + " failed with exception " + exception_message) {}
155
156
Invalid_Authentication_Tag::Invalid_Authentication_Tag(const std::string& msg) :
157
   Exception("Invalid authentication tag: " + msg)
158
726
   {}
159
160
Invalid_OID::Invalid_OID(const std::string& oid) :
161
   Decoding_Error("Invalid ASN.1 OID: " + oid)
162
0
   {}
163
164
Stream_IO_Error::Stream_IO_Error(const std::string& err) :
165
   Exception("I/O error: " + err)
166
16
   {}
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
0
   {}
172
173
Self_Test_Failure::Self_Test_Failure(const std::string& err) :
174
   Internal_Error("Self test failed: " + err)
175
0
   {}
176
177
Not_Implemented::Not_Implemented(const std::string& err) :
178
   Exception("Not implemented", err)
179
0
   {}
180
181
}