diff options
author | Hannes Rantzsch <[email protected]> | 2019-04-23 15:50:37 +0200 |
---|---|---|
committer | Hannes Rantzsch <[email protected]> | 2019-04-23 15:50:37 +0200 |
commit | 968beff9e28ff0f32e662dfd4fa8e5287cfd2abb (patch) | |
tree | 8e33a6397f400a59eb9236e8b0e06f414d041e56 /src/lib/tls/asio/asio_error.h | |
parent | af9b7c00733b837db793706c1b802b3e9ad5e07b (diff) |
use ErrorType instead of TLS::error and remove convert_exceptions header
Diffstat (limited to 'src/lib/tls/asio/asio_error.h')
-rw-r--r-- | src/lib/tls/asio/asio_error.h | 114 |
1 files changed, 32 insertions, 82 deletions
diff --git a/src/lib/tls/asio/asio_error.h b/src/lib/tls/asio/asio_error.h index 97b19395e..92f54ba7c 100644 --- a/src/lib/tls/asio/asio_error.h +++ b/src/lib/tls/asio/asio_error.h @@ -16,39 +16,13 @@ #include <boost/system/system_error.hpp> +#include <botan/exceptn.h> #include <botan/tls_alert.h> +#include <botan/tls_exceptn.h> namespace Botan { - namespace TLS { -enum class error - { - unexpected_message = 1, - invalid_argument, - unsupported_argument, - invalid_state, - key_not_set, - lookup_error, - internal_error, - invalid_key_length, - invalid_iv_length, - prng_unseeded, - policy_violation, - algorithm_not_found, - no_provider_found, - provider_not_found, - invalid_algorithm_name, - encoding_error, - decoding_error, - integrity_failure, - invalid_oid, - stream_io_error, - self_test_failure, - not_implemented, - unknown - }; - namespace detail { // TLS Alerts struct BotanAlertCategory : boost::system::error_category @@ -80,56 +54,7 @@ struct BotanErrorCategory : boost::system::error_category std::string message(int ev) const override { - switch(static_cast<error>(ev)) - { - case error::unexpected_message: - return "unexpected_message"; - case error::invalid_argument: - return "invalid_argument"; - case error::unsupported_argument: - return "unsupported_argument"; - case error::invalid_state: - return "invalid_state"; - case error::key_not_set: - return "key_not_set"; - case error::lookup_error: - return "lookup_error"; - case error::internal_error: - return "internal_error"; - case error::invalid_key_length: - return "invalid_key_length"; - case error::invalid_iv_length: - return "invalid_iv_length"; - case error::prng_unseeded: - return "prng_unseeded"; - case error::policy_violation: - return "policy_violation"; - case error::algorithm_not_found: - return "algorithm_not_found"; - case error::no_provider_found: - return "no_provider_found"; - case error::provider_not_found: - return "provider_not_found"; - case error::invalid_algorithm_name: - return "invalid_algorithm_name"; - case error::encoding_error: - return "encoding_error"; - case error::decoding_error: - return "decoding_error"; - case error::integrity_failure: - return "integrity_failure"; - case error::invalid_oid: - return "invalid_oid"; - case error::stream_io_error: - return "stream_io_error"; - case error::self_test_failure: - return "self_test_failure"; - case error::not_implemented: - return "not_implemented"; - - default: - return "(unrecognized botan tls error)"; - } + return Botan::to_string(static_cast<Botan::ErrorType>(ev)); } }; @@ -138,6 +63,7 @@ inline const BotanErrorCategory& botan_category() noexcept static BotanErrorCategory category; return category; } + } // namespace detail inline boost::system::error_code make_error_code(Botan::TLS::Alert::Type c) @@ -145,12 +71,13 @@ inline boost::system::error_code make_error_code(Botan::TLS::Alert::Type c) return boost::system::error_code(static_cast<int>(c), detail::botan_alert_category()); } -inline boost::system::error_code make_error_code(error c) +} // namespace TLS + +inline boost::system::error_code make_error_code(Botan::ErrorType e) { - return boost::system::error_code(static_cast<int>(c), detail::botan_category()); + return boost::system::error_code(static_cast<int>(e), Botan::TLS::detail::botan_category()); } -} // namespace TLS } // namespace Botan namespace boost { @@ -161,7 +88,7 @@ template<> struct is_error_code_enum<Botan::TLS::Alert::Type> static const bool value = true; }; -template<> struct is_error_code_enum<Botan::TLS::error> +template<> struct is_error_code_enum<Botan::ErrorType> { static const bool value = true; }; @@ -169,5 +96,28 @@ template<> struct is_error_code_enum<Botan::TLS::error> } // namespace system } // namespace boost +namespace Botan { +namespace TLS { + +inline boost::system::error_code convertException() + { + try + { + throw; + } + catch(const TLS_Exception& e) + { + return e.type(); + } + catch(const Botan::Exception& e) + { + return e.error_type(); + } + } + +} // namespace system +} // namespace boost + + #endif // BOOST_VERSION #endif // BOTAN_ASIO_ERROR_H_ |