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;
48enum StreamError : uint8_t { StreamTruncated = 1 };
51class StreamCategory final :
public BoostErrorCategory {
53 const char* name() const noexcept
override {
return "Botan TLS Stream"; }
55 std::string message(
int value)
const override {
56 if(value == StreamTruncated) {
57 return "stream truncated";
59 return "generic error";
64inline const StreamCategory& botan_stream_category() {
65 static const StreamCategory category;
69inline boost::system::error_code make_error_code(Botan::TLS::StreamError e) {
70 return boost::system::error_code(
static_cast<int>(e), Botan::TLS::botan_stream_category());
74class BotanAlertCategory final :
public BoostErrorCategory {
76 const char* name() const noexcept
override {
return "Botan TLS Alert"; }
78 std::string message(
int ev)
const override {
80 return alert.type_string();
84inline const BotanAlertCategory& botan_alert_category() noexcept {
85 static const BotanAlertCategory category;
90 return boost::system::error_code(
static_cast<int>(c), Botan::TLS::botan_alert_category());
96class BotanErrorCategory :
public BoostErrorCategory {
98 const char* name() const noexcept
override {
return "Botan"; }
103inline const BotanErrorCategory& botan_category() noexcept {
104 static const BotanErrorCategory category;
109 return boost::system::error_code(
static_cast<int>(e), Botan::botan_category());
118namespace boost::system {
121struct is_error_code_enum<Botan::TLS::Alert::Type> {
122 static const bool value =
true;
126struct is_error_code_enum<Botan::TLS::StreamError> {
127 static const bool value =
true;
131struct is_error_code_enum<Botan::
ErrorType> {
132 static const bool value =
true;
std::string to_string(ErrorType type)
Convert an ErrorType to string.