1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
#ifndef BOTAN_ASIO_ERROR_H_
#define BOTAN_ASIO_ERROR_H_
#include <boost/system/system_error.hpp>
#include <botan/tls_alert.h>
namespace Botan {
namespace TLS {
using error_code = boost::system::error_code;
using error_category = boost::system::error_category;
// TLS Alerts
struct BotanAlertCategory : error_category
{
const char* name() const noexcept override
{
return "asio.botan.tls.alert";
}
std::string message(int ev) const override
{
Botan::TLS::Alert alert(static_cast<Botan::TLS::Alert::Type>(ev));
return alert.type_string();
}
};
inline const BotanAlertCategory& botan_alert_category() noexcept
{
static BotanAlertCategory category;
return category;
}
inline error_code make_error_code(Botan::TLS::Alert::Type c)
{
return error_code(static_cast<int>(c), botan_alert_category());
}
enum class error
{
unexpected_message = 1,
invalid_argument,
unsupported_argument,
invalid_state,
key_not_set,
lookup_error,
internal_error,
invalid_key_length,
invalid_iv_length,
prng_unseeded,
policy_violation,
algorithm_not_found,
no_provider_found,
provider_not_found,
invalid_algorithm_name,
encoding_error,
decoding_error,
integrity_failure,
invalid_oid,
stream_io_error,
self_test_failure,
not_implemented,
unknown
};
struct BotanErrorCategory : error_category
{
const char* name() const noexcept override
{
return "asio.botan.tls";
}
std::string message(int ev) const override
{
switch(static_cast<error>(ev))
{
case error::unexpected_message:
return "unexpected_message";
case error::invalid_argument:
return "invalid_argument";
case error::unsupported_argument:
return "unsupported_argument";
case error::invalid_state:
return "invalid_state";
case error::key_not_set:
return "key_not_set";
case error::lookup_error:
return "lookup_error";
case error::internal_error:
return "internal_error";
case error::invalid_key_length:
return "invalid_key_length";
case error::invalid_iv_length:
return "invalid_iv_length";
case error::prng_unseeded:
return "prng_unseeded";
case error::policy_violation:
return "policy_violation";
case error::algorithm_not_found:
return "algorithm_not_found";
case error::no_provider_found:
return "no_provider_found";
case error::provider_not_found:
return "provider_not_found";
case error::invalid_algorithm_name:
return "invalid_algorithm_name";
case error::encoding_error:
return "encoding_error";
case error::decoding_error:
return "decoding_error";
case error::integrity_failure:
return "integrity_failure";
case error::invalid_oid:
return "invalid_oid";
case error::stream_io_error:
return "stream_io_error";
case error::self_test_failure:
return "self_test_failure";
case error::not_implemented:
return "not_implemented";
default:
return "(unrecognized botan tls error)";
}
}
};
inline const BotanErrorCategory& botan_category() noexcept
{
static BotanErrorCategory category;
return category;
}
inline error_code make_error_code(error c)
{
return error_code(static_cast<int>(c), botan_category());
}
} // namespace TLS
} // namespace Botan
namespace boost {
namespace system {
template<> struct is_error_code_enum<Botan::TLS::Alert::Type>
{
static const bool value = true;
};
template<> struct is_error_code_enum<Botan::TLS::error>
{
static const bool value = true;
};
} // namespace system
} // namespace boost
#endif
|