• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.7
/src/lib/utils/exceptn.cpp
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
#include <botan/internal/fmt.h>
10

11
namespace Botan {
12

13
std::string to_string(ErrorType type) {
×
14
   switch(type) {
×
15
      case ErrorType::Unknown:
×
16
         return "Unknown";
×
17
      case ErrorType::SystemError:
×
18
         return "SystemError";
×
19
      case ErrorType::NotImplemented:
×
20
         return "NotImplemented";
×
21
      case ErrorType::OutOfMemory:
×
22
         return "OutOfMemory";
×
23
      case ErrorType::InternalError:
×
24
         return "InternalError";
×
25
      case ErrorType::IoError:
×
26
         return "IoError";
×
27
      case ErrorType::InvalidObjectState:
×
28
         return "InvalidObjectState";
×
29
      case ErrorType::KeyNotSet:
×
30
         return "KeyNotSet";
×
31
      case ErrorType::InvalidArgument:
×
32
         return "InvalidArgument";
×
33
      case ErrorType::InvalidKeyLength:
×
34
         return "InvalidKeyLength";
×
35
      case ErrorType::InvalidNonceLength:
×
36
         return "InvalidNonceLength";
×
37
      case ErrorType::LookupError:
×
38
         return "LookupError";
×
39
      case ErrorType::EncodingFailure:
×
40
         return "EncodingFailure";
×
41
      case ErrorType::DecodingFailure:
×
42
         return "DecodingFailure";
×
43
      case ErrorType::TLSError:
×
44
         return "TLSError";
×
45
      case ErrorType::HttpError:
×
46
         return "HttpError";
×
47
      case ErrorType::InvalidTag:
×
48
         return "InvalidTag";
×
49
      case ErrorType::RoughtimeError:
×
50
         return "RoughtimeError";
×
51
      case ErrorType::CommonCryptoError:
×
52
         return "CommonCryptoError";
×
53
      case ErrorType::Pkcs11Error:
×
54
         return "Pkcs11Error";
×
55
      case ErrorType::TPMError:
×
56
         return "TPMError";
×
57
      case ErrorType::DatabaseError:
×
58
         return "DatabaseError";
×
59
      case ErrorType::ZlibError:
×
60
         return "ZlibError";
×
61
      case ErrorType::Bzip2Error:
×
62
         return "Bzip2Error";
×
63
      case ErrorType::LzmaError:
×
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(std::string_view msg) : m_msg(msg) {}
411,252✔
72

73
Exception::Exception(std::string_view msg, const std::exception& e) : m_msg(fmt("{} failed with {}", msg, e.what())) {}
8,649✔
74

75
Exception::Exception(const char* prefix, std::string_view msg) : m_msg(fmt("{} {}", prefix, msg)) {}
9,698✔
76

77
Invalid_Argument::Invalid_Argument(std::string_view msg) : Exception(msg) {}
14,023✔
78

79
Invalid_Argument::Invalid_Argument(std::string_view msg, std::string_view where) :
×
80
      Exception(fmt("{} in {}", msg, where)) {}
×
81

82
Invalid_Argument::Invalid_Argument(std::string_view msg, const std::exception& e) : Exception(msg, e) {}
×
83

84
namespace {
85

86
std::string format_lookup_error(std::string_view type, std::string_view algo, std::string_view provider) {
5✔
87
   if(provider.empty()) {
5✔
88
      return fmt("Unavailable {} {}", type, algo);
5✔
89
   } else {
90
      return fmt("Unavailable {} {} for provider {}", type, algo, provider);
×
91
   }
92
}
93

94
}  // namespace
95

96
Lookup_Error::Lookup_Error(std::string_view type, std::string_view algo, std::string_view provider) :
5✔
97
      Exception(format_lookup_error(type, algo, provider)) {}
10✔
98

99
Internal_Error::Internal_Error(std::string_view err) : Exception("Internal error:", err) {}
22✔
100

101
Unknown_PK_Field_Name::Unknown_PK_Field_Name(std::string_view algo_name, std::string_view field_name) :
6✔
102
      Invalid_Argument(fmt("Unknown field '{}' for algorithm {}", field_name, algo_name)) {}
12✔
103

104
Invalid_Key_Length::Invalid_Key_Length(std::string_view name, size_t length) :
×
105
      Invalid_Argument(fmt("{} cannot accept a key of length {}", name, length)) {}
×
106

107
Invalid_IV_Length::Invalid_IV_Length(std::string_view mode, size_t bad_len) :
6,032✔
108
      Invalid_Argument(fmt("IV length {} is invalid for {}", bad_len, mode)) {}
12,064✔
109

110
Key_Not_Set::Key_Not_Set(std::string_view algo) : Invalid_State(fmt("Key not set in {}", algo)) {}
173,856✔
111

112
PRNG_Unseeded::PRNG_Unseeded(std::string_view algo) : Invalid_State(fmt("PRNG {} not seeded", algo)) {}
46✔
113

114
Algorithm_Not_Found::Algorithm_Not_Found(std::string_view name) :
4,258✔
115
      Lookup_Error(fmt("Could not find any algorithm named '{}'", name)) {}
8,516✔
116

117
Provider_Not_Found::Provider_Not_Found(std::string_view algo, std::string_view provider) :
48,702✔
118
      Lookup_Error(fmt("Could not find provider '{}' for algorithm '{}'", provider, algo)) {}
97,404✔
119

120
Invalid_Algorithm_Name::Invalid_Algorithm_Name(std::string_view name) :
×
121
      Invalid_Argument(fmt("Invalid algorithm name: '{}'", name)) {}
×
122

123
Encoding_Error::Encoding_Error(std::string_view name) : Exception("Encoding error:", name) {}
279✔
124

125
Decoding_Error::Decoding_Error(std::string_view name) : Exception(name) {}
27,165✔
126

127
Decoding_Error::Decoding_Error(std::string_view category, std::string_view err) :
70✔
128
      Exception(fmt("{}: {}", category, err)) {}
140✔
129

130
Decoding_Error::Decoding_Error(std::string_view msg, const std::exception& e) : Exception(msg, e) {}
8,649✔
131

132
Invalid_Authentication_Tag::Invalid_Authentication_Tag(std::string_view msg) :
6,769✔
133
      Exception("Invalid authentication tag:", msg) {}
6,769✔
134

135
Stream_IO_Error::Stream_IO_Error(std::string_view err) : Exception("I/O error:", err) {}
206✔
136

137
System_Error::System_Error(std::string_view msg, int err_code) :
1✔
138
      Exception(fmt("{} error code {}", msg, err_code)), m_error_code(err_code) {}
2✔
139

140
Not_Implemented::Not_Implemented(std::string_view err) : Exception("Not implemented", err) {}
2,389✔
141

142
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc