Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom exception SslHandshakeError #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/oatpp-mbedtls/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@

namespace oatpp { namespace mbedtls {

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SslHandshakeError

Connection::SslHandshakeError::SslHandshakeError(v_int32 errorCode, const char* message)
: std::runtime_error(message)
, m_errorCode(errorCode)
, m_message(message)
{}

v_int32 Connection::SslHandshakeError::getErrorCode() const {
return m_errorCode;
}

const char* Connection::SslHandshakeError::getMessage() const {
return m_message;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ConnectionContext

Expand Down Expand Up @@ -96,9 +113,10 @@ void Connection::ConnectionContext::init() {
if(res == 0) {
break;
} else if (res != MBEDTLS_ERR_SSL_WANT_READ && res != MBEDTLS_ERR_SSL_WANT_WRITE) {
// v_char8 buff[512];
// mbedtls_strerror(res, (char *) &buff, 512);
// OATPP_LOGE("[oatpp::mbedtls::Connection::ConnectionContext::init()]", "Error. Handshake failed. Return value=%d. '%s'", res, buff);
v_char8 buff[512];
mbedtls_strerror(res, (char *)&buff, 512);
OATPP_LOGE("[oatpp::mbedtls::Connection::ConnectionContext::init()]", "Error. Handshake failed. Return value=%d. '%s'", res, buff);
throw SslHandshakeError(res, "[oatpp::mbedtls::Connection::ConnectionContext::init()]: Error. SSL Handshake failed");
break;
}

Expand Down
27 changes: 27 additions & 0 deletions src/oatpp-mbedtls/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,33 @@ class Connection : public oatpp::base::Countable, public oatpp::data::stream::IO
*/
provider::ResourceHandle<data::stream::IOStream> getTransportStream();

public:
class SslHandshakeError : public std::runtime_error {
private:
v_int32 m_errorCode;
const char* m_message;
public:

/**
* Constructor.
* @param errorCode - error code.
* @param message - error message.
*/
SslHandshakeError(v_int32 errorCode, const char* message);

/**
* Get error code.
* @return - error code.
*/
v_int32 getErrorCode() const;

/**
* Get error message.
* @return - error message.
*/
const char* getMessage() const;
};

};

}}
Expand Down