context_service.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // ssl/old/context_service.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
  6. // Copyright (c) 2005-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  7. //
  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)
  10. //
  11. #ifndef BOOST_ASIO_SSL_OLD_CONTEXT_SERVICE_HPP
  12. #define BOOST_ASIO_SSL_OLD_CONTEXT_SERVICE_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include <boost/asio/detail/config.hpp>
  17. #include <string>
  18. #include <boost/noncopyable.hpp>
  19. #include <boost/asio/error.hpp>
  20. #include <boost/asio/io_service.hpp>
  21. #include <boost/asio/ssl/context_base.hpp>
  22. #include <boost/asio/ssl/old/detail/openssl_context_service.hpp>
  23. #include <boost/asio/detail/push_options.hpp>
  24. namespace boost {
  25. namespace asio {
  26. namespace ssl {
  27. namespace old {
  28. /// Default service implementation for a context.
  29. class context_service
  30. #if defined(GENERATING_DOCUMENTATION)
  31. : public boost::asio::io_service::service
  32. #else
  33. : public boost::asio::detail::service_base<context_service>
  34. #endif
  35. {
  36. private:
  37. // The type of the platform-specific implementation.
  38. typedef old::detail::openssl_context_service service_impl_type;
  39. public:
  40. #if defined(GENERATING_DOCUMENTATION)
  41. /// The unique service identifier.
  42. static boost::asio::io_service::id id;
  43. #endif
  44. /// The type of the context.
  45. #if defined(GENERATING_DOCUMENTATION)
  46. typedef implementation_defined impl_type;
  47. #else
  48. typedef service_impl_type::impl_type impl_type;
  49. #endif
  50. /// Constructor.
  51. explicit context_service(boost::asio::io_service& io_service)
  52. : boost::asio::detail::service_base<context_service>(io_service),
  53. service_impl_(boost::asio::use_service<service_impl_type>(io_service))
  54. {
  55. }
  56. /// Return a null context implementation.
  57. impl_type null() const
  58. {
  59. return service_impl_.null();
  60. }
  61. /// Create a new context implementation.
  62. void create(impl_type& impl, context_base::method m)
  63. {
  64. service_impl_.create(impl, m);
  65. }
  66. /// Destroy a context implementation.
  67. void destroy(impl_type& impl)
  68. {
  69. service_impl_.destroy(impl);
  70. }
  71. /// Set options on the context.
  72. boost::system::error_code set_options(impl_type& impl,
  73. context_base::options o, boost::system::error_code& ec)
  74. {
  75. return service_impl_.set_options(impl, o, ec);
  76. }
  77. /// Set peer verification mode.
  78. boost::system::error_code set_verify_mode(impl_type& impl,
  79. context_base::verify_mode v, boost::system::error_code& ec)
  80. {
  81. return service_impl_.set_verify_mode(impl, v, ec);
  82. }
  83. /// Load a certification authority file for performing verification.
  84. boost::system::error_code load_verify_file(impl_type& impl,
  85. const std::string& filename, boost::system::error_code& ec)
  86. {
  87. return service_impl_.load_verify_file(impl, filename, ec);
  88. }
  89. /// Add a directory containing certification authority files to be used for
  90. /// performing verification.
  91. boost::system::error_code add_verify_path(impl_type& impl,
  92. const std::string& path, boost::system::error_code& ec)
  93. {
  94. return service_impl_.add_verify_path(impl, path, ec);
  95. }
  96. /// Use a certificate from a file.
  97. boost::system::error_code use_certificate_file(impl_type& impl,
  98. const std::string& filename, context_base::file_format format,
  99. boost::system::error_code& ec)
  100. {
  101. return service_impl_.use_certificate_file(impl, filename, format, ec);
  102. }
  103. /// Use a certificate chain from a file.
  104. boost::system::error_code use_certificate_chain_file(impl_type& impl,
  105. const std::string& filename, boost::system::error_code& ec)
  106. {
  107. return service_impl_.use_certificate_chain_file(impl, filename, ec);
  108. }
  109. /// Use a private key from a file.
  110. boost::system::error_code use_private_key_file(impl_type& impl,
  111. const std::string& filename, context_base::file_format format,
  112. boost::system::error_code& ec)
  113. {
  114. return service_impl_.use_private_key_file(impl, filename, format, ec);
  115. }
  116. /// Use an RSA private key from a file.
  117. boost::system::error_code use_rsa_private_key_file(impl_type& impl,
  118. const std::string& filename, context_base::file_format format,
  119. boost::system::error_code& ec)
  120. {
  121. return service_impl_.use_rsa_private_key_file(impl, filename, format, ec);
  122. }
  123. /// Use the specified file to obtain the temporary Diffie-Hellman parameters.
  124. boost::system::error_code use_tmp_dh_file(impl_type& impl,
  125. const std::string& filename, boost::system::error_code& ec)
  126. {
  127. return service_impl_.use_tmp_dh_file(impl, filename, ec);
  128. }
  129. /// Set the password callback.
  130. template <typename PasswordCallback>
  131. boost::system::error_code set_password_callback(impl_type& impl,
  132. PasswordCallback callback, boost::system::error_code& ec)
  133. {
  134. return service_impl_.set_password_callback(impl, callback, ec);
  135. }
  136. private:
  137. // Destroy all user-defined handler objects owned by the service.
  138. void shutdown_service()
  139. {
  140. }
  141. // The service that provides the platform-specific implementation.
  142. service_impl_type& service_impl_;
  143. };
  144. } // namespace old
  145. } // namespace ssl
  146. } // namespace asio
  147. } // namespace boost
  148. #include <boost/asio/detail/pop_options.hpp>
  149. #endif // BOOST_ASIO_SSL_OLD_CONTEXT_SERVICE_HPP