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>
34class BoostErrorCategory :
public boost::system::error_category {
36 virtual ~BoostErrorCategory() =
default;
38 BoostErrorCategory() =
default;
39 BoostErrorCategory(
const BoostErrorCategory& other) =
delete;
40 BoostErrorCategory(BoostErrorCategory&& other) =
delete;
41 BoostErrorCategory& operator=(
const BoostErrorCategory& other) =
delete;
42 BoostErrorCategory& operator=(BoostErrorCategory&& other) =
delete;
47enum StreamError : uint8_t { StreamTruncated = 1 };
50class StreamCategory final :
public BoostErrorCategory {
52 const char* name() const noexcept
override {
return "Botan TLS Stream"; }
54 std::string message(
int value)
const override {
55 if(value == StreamTruncated) {
56 return "stream truncated";
58 return "generic error";
63inline const StreamCategory& botan_stream_category() {
64 static StreamCategory category;
68inline boost::system::error_code make_error_code(Botan::TLS::StreamError e) {
69 return boost::system::error_code(
static_cast<int>(e), Botan::TLS::botan_stream_category());
73class BotanAlertCategory final :
public BoostErrorCategory {
75 const char* name() const noexcept
override {
return "Botan TLS Alert"; }
77 std::string message(
int ev)
const override {
79 return alert.type_string();
83inline const BotanAlertCategory& botan_alert_category() noexcept {
84 static BotanAlertCategory category;
89 return boost::system::error_code(
static_cast<int>(c), Botan::TLS::botan_alert_category());
95class BotanErrorCategory :
public BoostErrorCategory {
97 const char* name() const noexcept
override {
return "Botan"; }
102inline const BotanErrorCategory& botan_category() noexcept {
103 static BotanErrorCategory category;
108 return boost::system::error_code(
static_cast<int>(e), Botan::botan_category());
117namespace boost::system {
120struct is_error_code_enum<Botan::TLS::Alert::Type> {
121 static const bool value =
true;
125struct is_error_code_enum<Botan::TLS::StreamError> {
126 static const bool value =
true;
130struct is_error_code_enum<Botan::
ErrorType> {
131 static const bool value =
true;
std::string to_string(ErrorType type)
Convert an ErrorType to string.