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

randombit / botan / 5696981105

28 Jul 2023 12:55PM UTC coverage: 91.69% (+0.005%) from 91.685%
5696981105

push

github

randombit
Merge GH #3649 Remove some macros from loadstor.h

78267 of 85360 relevant lines covered (91.69%)

12322548.38 hits per line

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

62.07
/src/lib/tls/asio/asio_error.h
1
/*
2
* TLS Stream Errors
3
* (C) 2018-2020 Jack Lloyd
4
*     2018-2020 Hannes Rantzsch, Tim Oesterreich, Rene Meusel
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8

9
#ifndef BOTAN_ASIO_ERROR_H_
10
#define BOTAN_ASIO_ERROR_H_
11

12
#include <botan/types.h>
13

14
#include <boost/version.hpp>
15
#if BOOST_VERSION >= 106600
16

17
   #include <boost/system/system_error.hpp>
18

19
   #include <botan/exceptn.h>
20
   #include <botan/tls_alert.h>
21
   #include <botan/tls_exceptn.h>
22

23
/*
24
 * This file defines Botan-specific subclasses of boost::system::error_category.
25
 * In addition to the class definition, each category class is accompanied by function `make_error_code` used to create
26
 * a `boost::system::error_code` of the category from some other kind of error in Botan (for example, a TLS alert).
27
 * Since error_category instances should be singletons, there's also a method to get/create the instance for each class.
28
 */
29

30
namespace Botan {
31
namespace TLS {
32

33
enum StreamError { StreamTruncated = 1 };
34

35
//! @brief An error category for errors from the TLS::Stream
36
struct StreamCategory : public boost::system::error_category {
37
      virtual ~StreamCategory() = default;
1✔
38

39
      const char* name() const noexcept override { return "Botan TLS Stream"; }
×
40

41
      std::string message(int value) const override {
×
42
         if(value == StreamTruncated) {
×
43
            return "stream truncated";
×
44
         } else {
45
            return "generic error";
×
46
         }
47
      }
48
};
49

50
inline const StreamCategory& botan_stream_category() {
32✔
51
   static StreamCategory category;
32✔
52
   return category;
32✔
53
}
54

55
inline boost::system::error_code make_error_code(Botan::TLS::StreamError e) {
32✔
56
   return boost::system::error_code(static_cast<int>(e), Botan::TLS::botan_stream_category());
32✔
57
}
58

59
//! @brief An error category for TLS alerts
60
struct BotanAlertCategory : boost::system::error_category {
61
      virtual ~BotanAlertCategory() = default;
1✔
62

63
      const char* name() const noexcept override { return "Botan TLS Alert"; }
×
64

65
      std::string message(int ev) const override {
×
66
         Botan::TLS::Alert alert(static_cast<Botan::TLS::Alert::Type>(ev));
×
67
         return alert.type_string();
×
68
      }
69
};
70

71
inline const BotanAlertCategory& botan_alert_category() noexcept {
12✔
72
   static BotanAlertCategory category;
12✔
73
   return category;
12✔
74
}
75

76
inline boost::system::error_code make_error_code(Botan::TLS::Alert::Type c) {
12✔
77
   return boost::system::error_code(static_cast<int>(c), Botan::TLS::botan_alert_category());
12✔
78
}
79

80
}  // namespace TLS
81

82
//! @brief An error category for errors from Botan (other than TLS alerts)
83
struct BotanErrorCategory : boost::system::error_category {
84
      virtual ~BotanErrorCategory() = default;
1✔
85

86
      const char* name() const noexcept override { return "Botan"; }
×
87

88
      std::string message(int ev) const override { return Botan::to_string(static_cast<Botan::ErrorType>(ev)); }
×
89
};
90

91
inline const BotanErrorCategory& botan_category() noexcept {
1✔
92
   static BotanErrorCategory category;
1✔
93
   return category;
1✔
94
}
95

96
inline boost::system::error_code make_error_code(Botan::ErrorType e) {
1✔
97
   return boost::system::error_code(static_cast<int>(e), Botan::botan_category());
1✔
98
}
99

100
}  // namespace Botan
101

102
/*
103
 * Add a template specialization of `is_error_code_enum` for each kind of error to allow automatic conversion to an
104
 * error code.
105
 */
106
namespace boost::system {
107

108
template <>
109
struct is_error_code_enum<Botan::TLS::Alert::Type> {
110
      static const bool value = true;
111
};
112

113
template <>
114
struct is_error_code_enum<Botan::TLS::StreamError> {
115
      static const bool value = true;
116
};
117

118
template <>
119
struct is_error_code_enum<Botan::ErrorType> {
120
      static const bool value = true;
121
};
122

123
}  // namespace boost::system
124

125
#endif  // BOOST_VERSION
126
#endif  // BOTAN_ASIO_ERROR_H_
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