error.ipp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // ssl/impl/error.ipp
  3. // ~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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. #ifndef BOOST_ASIO_SSL_IMPL_ERROR_IPP
  11. #define BOOST_ASIO_SSL_IMPL_ERROR_IPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/ssl/error.hpp>
  17. #include <boost/asio/ssl/detail/openssl_init.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace error {
  22. namespace detail {
  23. class ssl_category : public boost::system::error_category
  24. {
  25. public:
  26. const char* name() const noexcept
  27. {
  28. return "asio.ssl";
  29. }
  30. std::string message(int value) const
  31. {
  32. const char* reason = ::ERR_reason_error_string(value);
  33. if (reason)
  34. {
  35. const char* lib = ::ERR_lib_error_string(value);
  36. #if (OPENSSL_VERSION_NUMBER < 0x30000000L)
  37. const char* func = ::ERR_func_error_string(value);
  38. #else // (OPENSSL_VERSION_NUMBER < 0x30000000L)
  39. const char* func = 0;
  40. #endif // (OPENSSL_VERSION_NUMBER < 0x30000000L)
  41. std::string result(reason);
  42. if (lib || func)
  43. {
  44. result += " (";
  45. if (lib)
  46. result += lib;
  47. if (lib && func)
  48. result += ", ";
  49. if (func)
  50. result += func;
  51. result += ")";
  52. }
  53. return result;
  54. }
  55. return "asio.ssl error";
  56. }
  57. };
  58. } // namespace detail
  59. const boost::system::error_category& get_ssl_category()
  60. {
  61. static detail::ssl_category instance;
  62. return instance;
  63. }
  64. } // namespace error
  65. namespace ssl {
  66. namespace error {
  67. #if (OPENSSL_VERSION_NUMBER < 0x10100000L) && !defined(OPENSSL_IS_BORINGSSL)
  68. const boost::system::error_category& get_stream_category()
  69. {
  70. return boost::asio::error::get_ssl_category();
  71. }
  72. #else
  73. namespace detail {
  74. class stream_category : public boost::system::error_category
  75. {
  76. public:
  77. const char* name() const noexcept
  78. {
  79. return "asio.ssl.stream";
  80. }
  81. std::string message(int value) const
  82. {
  83. switch (value)
  84. {
  85. case stream_truncated: return "stream truncated";
  86. case unspecified_system_error: return "unspecified system error";
  87. case unexpected_result: return "unexpected result";
  88. default: return "asio.ssl.stream error";
  89. }
  90. }
  91. };
  92. } // namespace detail
  93. const boost::system::error_category& get_stream_category()
  94. {
  95. static detail::stream_category instance;
  96. return instance;
  97. }
  98. #endif
  99. } // namespace error
  100. } // namespace ssl
  101. } // namespace asio
  102. } // namespace boost
  103. #include <boost/asio/detail/pop_options.hpp>
  104. #endif // BOOST_ASIO_SSL_IMPL_ERROR_IPP