1 //
2 // ssl/error.hpp
3 // ~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_SSL_ERROR_HPP
12 #define ASIO_SSL_ERROR_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include "asio/error_code.hpp"
20 
21 #include "asio/detail/push_options.hpp"
22 
23 namespace asio {
24 namespace error {
25 
26 enum ssl_errors
27 {
28   // Error numbers are those produced by openssl.
29 };
30 
31 extern ASIO_DECL
32 const asio::error_category& get_ssl_category();
33 
34 static const asio::error_category& ssl_category
35   = asio::error::get_ssl_category();
36 
37 } // namespace error
38 namespace ssl {
39 namespace error {
40 
41 enum stream_errors
42 {
43 #if defined(GENERATING_DOCUMENTATION)
44   /// The underlying stream closed before the ssl stream gracefully shut down.
45   stream_truncated
46 #elif (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL)
47   stream_truncated = ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ)
48 #else
49   stream_truncated = 1
50 #endif
51 };
52 
53 extern ASIO_DECL
54 const asio::error_category& get_stream_category();
55 
56 static const asio::error_category& stream_category
57   = asio::ssl::error::get_stream_category();
58 
59 } // namespace error
60 } // namespace ssl
61 } // namespace asio
62 
63 #if defined(ASIO_HAS_STD_SYSTEM_ERROR)
64 namespace std {
65 
66 template<> struct is_error_code_enum<asio::error::ssl_errors>
67 {
68   static const bool value = true;
69 };
70 
71 template<> struct is_error_code_enum<asio::ssl::error::stream_errors>
72 {
73   static const bool value = true;
74 };
75 
76 } // namespace std
77 #endif // defined(ASIO_HAS_STD_SYSTEM_ERROR)
78 
79 namespace asio {
80 namespace error {
81 
make_error_code(ssl_errors e)82 inline asio::error_code make_error_code(ssl_errors e)
83 {
84   return asio::error_code(
85       static_cast<int>(e), get_ssl_category());
86 }
87 
88 } // namespace error
89 namespace ssl {
90 namespace error {
91 
make_error_code(stream_errors e)92 inline asio::error_code make_error_code(stream_errors e)
93 {
94   return asio::error_code(
95       static_cast<int>(e), get_stream_category());
96 }
97 
98 } // namespace error
99 } // namespace ssl
100 } // namespace asio
101 
102 #include "asio/detail/pop_options.hpp"
103 
104 #if defined(ASIO_HEADER_ONLY)
105 # include "asio/ssl/impl/error.ipp"
106 #endif // defined(ASIO_HEADER_ONLY)
107 
108 #endif // ASIO_SSL_ERROR_HPP
109