aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorHannes Rantzsch <[email protected]>2019-04-23 15:50:37 +0200
committerHannes Rantzsch <[email protected]>2019-04-23 15:50:37 +0200
commit968beff9e28ff0f32e662dfd4fa8e5287cfd2abb (patch)
tree8e33a6397f400a59eb9236e8b0e06f414d041e56 /src/lib
parentaf9b7c00733b837db793706c1b802b3e9ad5e07b (diff)
use ErrorType instead of TLS::error and remove convert_exceptions header
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/tls/asio/asio_async_handshake_op.h1
-rw-r--r--src/lib/tls/asio/asio_async_read_op.h1
-rw-r--r--src/lib/tls/asio/asio_convert_exceptions.h137
-rw-r--r--src/lib/tls/asio/asio_error.h114
-rw-r--r--src/lib/tls/asio/asio_stream.h19
-rw-r--r--src/lib/tls/asio/asio_stream_base.h2
-rw-r--r--src/lib/tls/asio/info.txt1
-rw-r--r--src/lib/utils/exceptn.cpp58
-rw-r--r--src/lib/utils/exceptn.h2
9 files changed, 103 insertions, 232 deletions
diff --git a/src/lib/tls/asio/asio_async_handshake_op.h b/src/lib/tls/asio/asio_async_handshake_op.h
index 6bb895ff2..670af373c 100644
--- a/src/lib/tls/asio/asio_async_handshake_op.h
+++ b/src/lib/tls/asio/asio_async_handshake_op.h
@@ -15,7 +15,6 @@
#if BOOST_VERSION >= 106600
#include <botan/internal/asio_async_write_op.h>
-#include <botan/internal/asio_convert_exceptions.h>
#include <botan/internal/asio_includes.h>
#include <botan/internal/asio_stream_core.h>
diff --git a/src/lib/tls/asio/asio_async_read_op.h b/src/lib/tls/asio/asio_async_read_op.h
index 52c63cea5..b15e273b9 100644
--- a/src/lib/tls/asio/asio_async_read_op.h
+++ b/src/lib/tls/asio/asio_async_read_op.h
@@ -15,7 +15,6 @@
#if BOOST_VERSION >= 106600
#include <botan/internal/asio_async_base.h>
-#include <botan/internal/asio_convert_exceptions.h>
#include <botan/internal/asio_includes.h>
#include <botan/internal/asio_stream_core.h>
diff --git a/src/lib/tls/asio/asio_convert_exceptions.h b/src/lib/tls/asio/asio_convert_exceptions.h
deleted file mode 100644
index 305726c04..000000000
--- a/src/lib/tls/asio/asio_convert_exceptions.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
-* TLS Stream Helper
-* (C) 2018-2019 Jack Lloyd
-* 2018-2019 Hannes Rantzsch, Tim Oesterreich, Rene Meusel
-*
-* Botan is released under the Simplified BSD License (see license.txt)
-*/
-
-#ifndef BOTAN_ASIO_CONVERT_EXCEPTIONS_H_
-#define BOTAN_ASIO_CONVERT_EXCEPTIONS_H_
-
-#include <botan/build.h>
-
-#include <boost/version.hpp>
-#if BOOST_VERSION >= 106600
-
-#include <botan/asio_error.h>
-#include <botan/tls_exceptn.h>
-
-namespace Botan {
-
-namespace TLS {
-
-inline boost::system::error_code convertException()
- {
- try
- {
- throw;
- }
- catch(const Botan::TLS::Unexpected_Message&)
- {
- return Botan::TLS::error::unexpected_message;
- }
- catch(const Botan::TLS::TLS_Exception& e)
- {
- return e.type();
- }
- catch(const Botan::Unsupported_Argument&)
- {
- return Botan::TLS::error::unsupported_argument;
- }
- catch(const Botan::Invalid_Key_Length&)
- {
- return Botan::TLS::error::invalid_key_length;
- }
- catch(const Botan::Invalid_IV_Length&)
- {
- return Botan::TLS::error::invalid_iv_length;
- }
- catch(const Botan::Invalid_Algorithm_Name&)
- {
- return Botan::TLS::error::invalid_algorithm_name;
- }
- catch(const Botan::Encoding_Error&)
- {
- return Botan::TLS::error::encoding_error;
- }
- catch(const Botan::Invalid_OID&)
- {
- return Botan::TLS::error::invalid_oid;
- }
- catch(const Botan::Decoding_Error&)
- {
- return Botan::TLS::error::decoding_error;
- }
- catch(const Botan::Invalid_Argument&)
- {
- return Botan::TLS::error::invalid_argument;
- }
- catch(const Botan::Key_Not_Set&)
- {
- return Botan::TLS::error::key_not_set;
- }
- catch(const Botan::PRNG_Unseeded&)
- {
- return Botan::TLS::error::prng_unseeded;
- }
- catch(const Botan::Policy_Violation&)
- {
- return Botan::TLS::error::policy_violation;
- }
- catch(const Botan::Invalid_State&)
- {
- return Botan::TLS::error::invalid_state;
- }
- catch(const Botan::Algorithm_Not_Found&)
- {
- return Botan::TLS::error::algorithm_not_found;
- }
- catch(const Botan::Provider_Not_Found&)
- {
- return Botan::TLS::error::provider_not_found;
- }
- catch(const Botan::Lookup_Error&)
- {
- return Botan::TLS::error::lookup_error;
- }
- catch(const Botan::Self_Test_Failure&)
- {
- return Botan::TLS::error::self_test_failure;
- }
- catch(const Botan::Internal_Error&)
- {
- return Botan::TLS::error::internal_error;
- }
- catch(const Botan::No_Provider_Found&)
- {
- return Botan::TLS::error::no_provider_found;
- }
- catch(const Botan::Integrity_Failure&)
- {
- return Botan::TLS::error::integrity_failure;
- }
- catch(const Botan::Stream_IO_Error&)
- {
- return Botan::TLS::error::stream_io_error;
- }
- catch(const Botan::Not_Implemented&)
- {
- return Botan::TLS::error::not_implemented;
- }
- catch(const Botan::Exception&)
- {
- return Botan::TLS::error::unknown;
- }
- catch(const std::exception&)
- {
- return Botan::TLS::error::unknown;
- }
- }
-
-} // namespace TLS
-
-} // namespace Botan
-
-#endif // BOOST_VERSION
-#endif // BOTAN_ASIO_CONVERT_EXCEPTIONS_H_
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_
diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h
index e19cbf0e7..8318c3c4e 100644
--- a/src/lib/tls/asio/asio_stream.h
+++ b/src/lib/tls/asio/asio_stream.h
@@ -15,10 +15,11 @@
#include <boost/version.hpp>
#if BOOST_VERSION >= 106600
+#include <botan/asio_error.h>
+
#include <botan/internal/asio_async_handshake_op.h>
#include <botan/internal/asio_async_read_op.h>
#include <botan/internal/asio_async_write_op.h>
-#include <botan/internal/asio_convert_exceptions.h>
#include <botan/internal/asio_includes.h>
#include <botan/internal/asio_stream_base.h>
#include <botan/internal/asio_stream_core.h>
@@ -95,14 +96,14 @@ class Stream : public StreamBase<Channel>
/**
* Not Implemented.
- * @param ec Will be set to `Botan::TLS::error::not_implemented`
+ * @param ec Will be set to `Botan::ErrorType::NotImplemented`
*/
template<typename VerifyCallback>
void set_verify_callback(VerifyCallback callback,
boost::system::error_code& ec)
{
BOTAN_UNUSED(callback);
- ec = Botan::TLS::error::not_implemented;
+ ec = Botan::ErrorType::NotImplemented;
}
/**
@@ -116,13 +117,13 @@ class Stream : public StreamBase<Channel>
/**
* Not Implemented.
- * @param ec Will be set to `Botan::TLS::error::not_implemented`
+ * @param ec Will be set to `Botan::ErrorType::NotImplemented`
*/
void set_verify_depth(int depth,
boost::system::error_code& ec)
{
BOTAN_UNUSED(depth);
- ec = Botan::TLS::error::not_implemented;
+ ec = Botan::ErrorType::NotImplemented;
}
/**
@@ -137,14 +138,14 @@ class Stream : public StreamBase<Channel>
/**
* Not Implemented.
- * @param ec Will be set to `Botan::TLS::error::not_implemented`
+ * @param ec Will be set to `Botan::ErrorType::NotImplemented`
*/
template <typename verify_mode>
void set_verify_mode(verify_mode v,
boost::system::error_code& ec)
{
BOTAN_UNUSED(v);
- ec = Botan::TLS::error::not_implemented;
+ ec = Botan::ErrorType::NotImplemented;
}
//
@@ -286,7 +287,7 @@ class Stream : public StreamBase<Channel>
/**
* Not Implemented.
- * @param ec Will be set to `Botan::TLS::error::not_implemented`
+ * @param ec Will be set to `Botan::ErrorType::NotImplemented`
*/
template<typename ConstBufferSequence>
void handshake(Connection_Side side,
@@ -295,7 +296,7 @@ class Stream : public StreamBase<Channel>
{
BOTAN_UNUSED(buffers);
if(validate_connection_side(side, ec))
- { ec = Botan::TLS::error::not_implemented; }
+ { ec = Botan::ErrorType::NotImplemented; }
}
/**
diff --git a/src/lib/tls/asio/asio_stream_base.h b/src/lib/tls/asio/asio_stream_base.h
index f1c43254e..9a9cc568b 100644
--- a/src/lib/tls/asio/asio_stream_base.h
+++ b/src/lib/tls/asio/asio_stream_base.h
@@ -69,7 +69,7 @@ class StreamBase<Botan::TLS::Client>
{
if(side != CLIENT)
{
- ec = Botan::TLS::error::invalid_argument;
+ ec = Botan::ErrorType::InvalidArgument;
return false;
}
diff --git a/src/lib/tls/asio/info.txt b/src/lib/tls/asio/info.txt
index 73afbb960..075ecb795 100644
--- a/src/lib/tls/asio/info.txt
+++ b/src/lib/tls/asio/info.txt
@@ -13,7 +13,6 @@ asio_async_base.h
asio_async_handshake_op.h
asio_async_read_op.h
asio_async_write_op.h
-asio_convert_exceptions.h
asio_stream_base.h
asio_stream_core.h
asio_includes.h
diff --git a/src/lib/utils/exceptn.cpp b/src/lib/utils/exceptn.cpp
index 78365f98b..3876c3b26 100644
--- a/src/lib/utils/exceptn.cpp
+++ b/src/lib/utils/exceptn.cpp
@@ -8,6 +8,64 @@
namespace Botan {
+std::string to_string(ErrorType type)
+{
+ switch(type)
+ {
+ case ErrorType::Unknown:
+ return "Unknown";
+ case ErrorType::SystemError:
+ return "SystemError";
+ case ErrorType::NotImplemented:
+ return "NotImplemented";
+ case ErrorType::OutOfMemory:
+ return "OutOfMemory";
+ case ErrorType::InternalError:
+ return "InternalError";
+ case ErrorType::IoError:
+ return "IoError";
+ case ErrorType::InvalidObjectState :
+ return "InvalidObjectState";
+ case ErrorType::KeyNotSet:
+ return "KeyNotSet";
+ case ErrorType::InvalidArgument:
+ return "InvalidArgument";
+ case ErrorType::InvalidKeyLength:
+ return "InvalidKeyLength";
+ case ErrorType::InvalidNonceLength:
+ return "InvalidNonceLength";
+ case ErrorType::LookupError:
+ return "LookupError";
+ case ErrorType::EncodingFailure:
+ return "EncodingFailure";
+ case ErrorType::DecodingFailure:
+ return "DecodingFailure";
+ case ErrorType::TLSError:
+ return "TLSError";
+ case ErrorType::HttpError:
+ return "HttpError";
+ case ErrorType::InvalidTag:
+ return "InvalidTag";
+ case ErrorType::OpenSSLError :
+ return "OpenSSLError";
+ case ErrorType::CommonCryptoError:
+ return "CommonCryptoError";
+ case ErrorType::Pkcs11Error:
+ return "Pkcs11Error";
+ case ErrorType::TPMError:
+ return "TPMError";
+ case ErrorType::ZlibError :
+ return "ZlibError";
+ case ErrorType::Bzip2Error:
+ return "Bzip2Error" ;
+ case ErrorType::LzmaError:
+ return "LzmaError";
+
+ default:
+ return "unrecognized botan error";
+ }
+}
+
Exception::Exception(const std::string& msg) : m_msg(msg)
{}
diff --git a/src/lib/utils/exceptn.h b/src/lib/utils/exceptn.h
index c4934ed04..801cacdb2 100644
--- a/src/lib/utils/exceptn.h
+++ b/src/lib/utils/exceptn.h
@@ -72,6 +72,8 @@ enum class ErrorType {
};
+std::string BOTAN_PUBLIC_API(2,0) to_string(ErrorType type);
+
/**
* Base class for all exceptions thrown by the library
*/