error.ipp 2.6 KB

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