5 // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
6 // Copyright (c) 2005-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
12 #ifndef BOOST_ASIO_SSL_CONTEXT_SERVICE_HPP
13 #define BOOST_ASIO_SSL_CONTEXT_SERVICE_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/asio/detail/push_options.hpp>
21 #include <boost/asio/detail/push_options.hpp>
23 #include <boost/noncopyable.hpp>
24 #include <boost/asio/detail/pop_options.hpp>
26 #include <boost/asio/error.hpp>
27 #include <boost/asio/io_service.hpp>
28 #include <boost/asio/detail/service_base.hpp>
29 #include <boost/asio/ssl/context_base.hpp>
30 #include <boost/asio/ssl/detail/openssl_context_service.hpp>
36 /// Default service implementation for a context.
38 #if defined(GENERATING_DOCUMENTATION)
39 : public boost::asio::io_service::service
41 : public boost::asio::detail::service_base
<context_service
>
45 // The type of the platform-specific implementation.
46 typedef detail::openssl_context_service service_impl_type
;
49 #if defined(GENERATING_DOCUMENTATION)
50 /// The unique service identifier.
51 static boost::asio::io_service::id id
;
54 /// The type of the context.
55 #if defined(GENERATING_DOCUMENTATION)
56 typedef implementation_defined impl_type
;
58 typedef service_impl_type::impl_type impl_type
;
62 explicit context_service(boost::asio::io_service
& io_service
)
63 : boost::asio::detail::service_base
<context_service
>(io_service
),
64 service_impl_(boost::asio::use_service
<service_impl_type
>(io_service
))
68 /// Destroy all user-defined handler objects owned by the service.
69 void shutdown_service()
73 /// Return a null context implementation.
74 impl_type
null() const
76 return service_impl_
.null();
79 /// Create a new context implementation.
80 void create(impl_type
& impl
, context_base::method m
)
82 service_impl_
.create(impl
, m
);
85 /// Destroy a context implementation.
86 void destroy(impl_type
& impl
)
88 service_impl_
.destroy(impl
);
91 /// Set options on the context.
92 boost::system::error_code
set_options(impl_type
& impl
,
93 context_base::options o
, boost::system::error_code
& ec
)
95 return service_impl_
.set_options(impl
, o
, ec
);
98 /// Set peer verification mode.
99 boost::system::error_code
set_verify_mode(impl_type
& impl
,
100 context_base::verify_mode v
, boost::system::error_code
& ec
)
102 return service_impl_
.set_verify_mode(impl
, v
, ec
);
105 /// Load a certification authority file for performing verification.
106 boost::system::error_code
load_verify_file(impl_type
& impl
,
107 const std::string
& filename
, boost::system::error_code
& ec
)
109 return service_impl_
.load_verify_file(impl
, filename
, ec
);
112 /// Add a directory containing certification authority files to be used for
113 /// performing verification.
114 boost::system::error_code
add_verify_path(impl_type
& impl
,
115 const std::string
& path
, boost::system::error_code
& ec
)
117 return service_impl_
.add_verify_path(impl
, path
, ec
);
120 /// Use a certificate from a file.
121 boost::system::error_code
use_certificate_file(impl_type
& impl
,
122 const std::string
& filename
, context_base::file_format format
,
123 boost::system::error_code
& ec
)
125 return service_impl_
.use_certificate_file(impl
, filename
, format
, ec
);
128 /// Use a certificate chain from a file.
129 boost::system::error_code
use_certificate_chain_file(impl_type
& impl
,
130 const std::string
& filename
, boost::system::error_code
& ec
)
132 return service_impl_
.use_certificate_chain_file(impl
, filename
, ec
);
135 /// Use a private key from a file.
136 boost::system::error_code
use_private_key_file(impl_type
& impl
,
137 const std::string
& filename
, context_base::file_format format
,
138 boost::system::error_code
& ec
)
140 return service_impl_
.use_private_key_file(impl
, filename
, format
, ec
);
143 /// Use an RSA private key from a file.
144 boost::system::error_code
use_rsa_private_key_file(impl_type
& impl
,
145 const std::string
& filename
, context_base::file_format format
,
146 boost::system::error_code
& ec
)
148 return service_impl_
.use_rsa_private_key_file(impl
, filename
, format
, ec
);
151 /// Use the specified file to obtain the temporary Diffie-Hellman parameters.
152 boost::system::error_code
use_tmp_dh_file(impl_type
& impl
,
153 const std::string
& filename
, boost::system::error_code
& ec
)
155 return service_impl_
.use_tmp_dh_file(impl
, filename
, ec
);
158 /// Set the password callback.
159 template <typename PasswordCallback
>
160 boost::system::error_code
set_password_callback(impl_type
& impl
,
161 PasswordCallback callback
, boost::system::error_code
& ec
)
163 return service_impl_
.set_password_callback(impl
, callback
, ec
);
167 // The service that provides the platform-specific implementation.
168 service_impl_type
& service_impl_
;
175 #include <boost/asio/detail/pop_options.hpp>
177 #endif // BOOST_ASIO_SSL_CONTEXT_SERVICE_HPP