Coverage Report

Created: 2023-02-22 06:14

/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::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
67
   // 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
6.01k
   {}
73
74
Exception::Exception(const std::string& msg, const std::exception& e) :
75
   m_msg(msg + " failed with " + std::string(e.what()))
76
0
   {}
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
5.18k
   {}
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
0
   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
0
   {}
103
104
Unknown_PK_Field_Name::Unknown_PK_Field_Name(const std::string& algo_name,
105
                                             const std::string& field_name) :
106
   Invalid_Argument("Unknown field '" + field_name +
107
                    "' for algorithm " + algo_name)
108
0
   {}
109
110
Invalid_Key_Length::Invalid_Key_Length(const std::string& name, size_t length) :
111
   Invalid_Argument(name + " cannot accept a key of length " +
112
                    std::to_string(length))
113
1.38k
   {}
114
115
Invalid_IV_Length::Invalid_IV_Length(const std::string& mode, size_t bad_len) :
116
   Invalid_Argument("IV length " + std::to_string(bad_len) +
117
                    " is invalid for " + mode)
118
288
   {}
119
120
Key_Not_Set::Key_Not_Set(const std::string& algo) :
121
   Invalid_State("Key not set in " + algo)
122
0
   {}
123
124
PRNG_Unseeded::PRNG_Unseeded(const std::string& algo) :
125
   Invalid_State("PRNG not seeded: " + algo)
126
0
   {}
127
128
Algorithm_Not_Found::Algorithm_Not_Found(const std::string& name) :
129
   Lookup_Error("Could not find any algorithm named \"" + name + "\"")
130
0
   {}
131
132
Provider_Not_Found::Provider_Not_Found(const std::string& algo, const std::string& provider) :
133
   Lookup_Error("Could not find provider '" + provider + "' for " + algo)
134
0
   {}
135
136
Invalid_Algorithm_Name::Invalid_Algorithm_Name(const std::string& name):
137
   Invalid_Argument("Invalid algorithm name: " + name)
138
0
   {}
139
140
Encoding_Error::Encoding_Error(const std::string& name) :
141
   Exception("Encoding error: " + name)
142
98
   {}
143
144
Decoding_Error::Decoding_Error(const std::string& name) :
145
   Exception(name)
146
213
   {}
147
148
Decoding_Error::Decoding_Error(const std::string& msg, const std::exception& e) :
149
   Exception(msg, e)
150
0
   {}
151
152
Decoding_Error::Decoding_Error(const std::string& name, const char* exception_message) :
153
0
   Exception(name + " failed with exception " + exception_message) {}
154
155
Invalid_Authentication_Tag::Invalid_Authentication_Tag(const std::string& msg) :
156
   Exception("Invalid authentication tag: " + msg)
157
408
   {}
158
159
Stream_IO_Error::Stream_IO_Error(const std::string& err) :
160
   Exception("I/O error: " + err)
161
0
   {}
162
163
System_Error::System_Error(const std::string& msg, int err_code) :
164
   Exception(msg + " error code " + std::to_string(err_code)),
165
   m_error_code(err_code)
166
0
   {}
167
168
Not_Implemented::Not_Implemented(const std::string& err) :
169
   Exception("Not implemented", err)
170
0
   {}
171
172
}