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

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 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,244✔
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,018✔
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
}  // namespace
94

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

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

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

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

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

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

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

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

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

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

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

124
Decoding_Error::Decoding_Error(std::string_view name) : Exception(name) {}
27,154✔
125

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

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

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

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

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

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

141
}  // 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