Botan  2.11.0
Crypto and TLS for C++11
asio_error.h
Go to the documentation of this file.
1 /*
2 * TLS Stream Errors
3 * (C) 2018-2019 Jack Lloyd
4 * 2018-2019 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/build.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 namespace Botan {
24 namespace TLS {
25 
26 //! @brief An error category for TLS alerts
27 struct BotanAlertCategory : boost::system::error_category
28  {
29  const char* name() const noexcept override
30  {
31  return "asio.botan.tls.alert";
32  }
33 
34  std::string message(int ev) const override
35  {
36  Botan::TLS::Alert alert(static_cast<Botan::TLS::Alert::Type>(ev));
37  return alert.type_string();
38  }
39  };
40 
41 inline const BotanAlertCategory& botan_alert_category() noexcept
42  {
43  static BotanAlertCategory category;
44  return category;
45  }
46 
47 inline boost::system::error_code make_error_code(Botan::TLS::Alert::Type c)
48  {
49  return boost::system::error_code(static_cast<int>(c), Botan::TLS::botan_alert_category());
50  }
51 
52 } // namespace TLS
53 
54 //! @brief An error category for errors from Botan (other than TLS alerts)
55 struct BotanErrorCategory : boost::system::error_category
56  {
57  const char* name() const noexcept override
58  {
59  return "asio.botan.tls";
60  }
61 
62  std::string message(int ev) const override
63  {
64  return Botan::to_string(static_cast<Botan::ErrorType>(ev));
65  }
66  };
67 
68 inline const BotanErrorCategory& botan_category() noexcept
69  {
70  static BotanErrorCategory category;
71  return category;
72  }
73 
74 inline boost::system::error_code make_error_code(Botan::ErrorType e)
75  {
76  return boost::system::error_code(static_cast<int>(e), Botan::botan_category());
77  }
78 
79 } // namespace Botan
80 
81 namespace boost {
82 namespace system {
83 
84 template<> struct is_error_code_enum<Botan::TLS::Alert::Type>
85  {
86  static const bool value = true;
87  };
88 
89 template<> struct is_error_code_enum<Botan::ErrorType>
90  {
91  static const bool value = true;
92  };
93 
94 } // namespace system
95 } // namespace boost
96 
97 #endif // BOOST_VERSION
98 #endif // BOTAN_ASIO_ERROR_H_
const BotanErrorCategory & botan_category() noexcept
Definition: asio_error.h:68
boost::system::error_code make_error_code(Botan::TLS::Alert::Type c)
Definition: asio_error.h:47
An error category for TLS alerts.
Definition: asio_error.h:27
boost::system::error_code make_error_code(Botan::ErrorType e)
Definition: asio_error.h:74
const BotanAlertCategory & botan_alert_category() noexcept
Definition: asio_error.h:41
std::string type_string() const
Definition: tls_alert.cpp:39
std::string message(int ev) const override
Definition: asio_error.h:62
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition: exceptn.cpp:11
const char * name() const noexcept override
Definition: asio_error.h:57
ErrorType
Definition: exceptn.h:20
Definition: alg_id.cpp:13
std::string message(int ev) const override
Definition: asio_error.h:34
const char * name() const noexcept override
Definition: asio_error.h:29
An error category for errors from Botan (other than TLS alerts)
Definition: asio_error.h:55