9#ifndef BOTAN_ASIO_ERROR_H_
10#define BOTAN_ASIO_ERROR_H_
12#include <botan/asio_compat.h>
13#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_ASIO_VERSION)
15 #include <boost/system/system_error.hpp>
17 #include <botan/exceptn.h>
18 #include <botan/tls_alert.h>
19 #include <botan/tls_exceptn.h>
31enum StreamError { StreamTruncated = 1 };
34struct StreamCategory :
public boost::system::error_category {
35 virtual ~StreamCategory() =
default;
37 const char*
name() const noexcept
override {
return "Botan TLS Stream"; }
39 std::string message(
int value)
const override {
40 if(value == StreamTruncated) {
41 return "stream truncated";
43 return "generic error";
48inline const StreamCategory& botan_stream_category() {
49 static StreamCategory category;
53inline boost::system::error_code make_error_code(Botan::TLS::StreamError e) {
54 return boost::system::error_code(
static_cast<int>(e), Botan::TLS::botan_stream_category());
58struct BotanAlertCategory : boost::system::error_category {
59 virtual ~BotanAlertCategory() =
default;
61 const char*
name() const noexcept
override {
return "Botan TLS Alert"; }
63 std::string message(
int ev)
const override {
65 return alert.type_string();
69inline const BotanAlertCategory& botan_alert_category() noexcept {
70 static BotanAlertCategory category;
75 return boost::system::error_code(
static_cast<int>(c), Botan::TLS::botan_alert_category());
81struct BotanErrorCategory : boost::system::error_category {
82 virtual ~BotanErrorCategory() =
default;
84 const char*
name() const noexcept
override {
return "Botan"; }
89inline const BotanErrorCategory& botan_category() noexcept {
90 static BotanErrorCategory category;
95 return boost::system::error_code(
static_cast<int>(e), Botan::botan_category());
104namespace boost::system {
107struct is_error_code_enum<
Botan::TLS::Alert::Type> {
108 static const bool value =
true;
112struct is_error_code_enum<
Botan::TLS::StreamError> {
113 static const bool value =
true;
118 static const bool value =
true;
std::string to_string(ErrorType type)
Convert an ErrorType to string.