Added support for completely disabling noexcept using MIJIN_TEST_NO_NOEXCEPT (for testing).
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <openssl/x509_vfy.h>
|
||||
|
||||
#include "../debug/assert.hpp"
|
||||
#include "../internal/common.hpp"
|
||||
#include "../types/result.hpp"
|
||||
|
||||
namespace ossl
|
||||
@@ -34,10 +35,10 @@ struct [[nodiscard]] Error
|
||||
std::vector<ErrorFrame> frames;
|
||||
|
||||
[[nodiscard]]
|
||||
bool isSuccess() const noexcept { return sslError == SSL_ERROR_NONE; }
|
||||
bool isSuccess() const MIJIN_NOEXCEPT { return sslError == SSL_ERROR_NONE; }
|
||||
|
||||
static inline Error current(int sslError = -1) noexcept;
|
||||
static inline Error current(SSL* handle, int result) noexcept { return current(SSL_get_error(handle, result)); }
|
||||
static inline Error current(int sslError = -1) MIJIN_NOEXCEPT;
|
||||
static inline Error current(SSL* handle, int result) MIJIN_NOEXCEPT { return current(SSL_get_error(handle, result)); }
|
||||
};
|
||||
template<typename TSuccess>
|
||||
using Result = mijin::ResultBase<TSuccess, Error>;
|
||||
@@ -53,24 +54,24 @@ protected:
|
||||
|
||||
THandle handle_ = nullptr;
|
||||
protected:
|
||||
explicit Base(THandle handle) noexcept : handle_(handle) {}
|
||||
explicit Base(THandle handle) MIJIN_NOEXCEPT : handle_(handle) {}
|
||||
public:
|
||||
Base() noexcept = default;
|
||||
Base(const Base& other) noexcept : handle_(other.handle_)
|
||||
Base() MIJIN_NOEXCEPT = default;
|
||||
Base(const Base& other) MIJIN_NOEXCEPT : handle_(other.handle_)
|
||||
{
|
||||
if (handle_)
|
||||
{
|
||||
TActual::upReferences(handle_);
|
||||
}
|
||||
}
|
||||
Base(Base&& other) noexcept : handle_(std::exchange(other.handle_, {})) {}
|
||||
Base(Base&& other) MIJIN_NOEXCEPT : handle_(std::exchange(other.handle_, {})) {}
|
||||
|
||||
~Base() noexcept
|
||||
~Base() MIJIN_NOEXCEPT
|
||||
{
|
||||
static_cast<TActual&>(*this).free();
|
||||
}
|
||||
|
||||
TActual& operator=(const Base& other) noexcept
|
||||
TActual& operator=(const Base& other) MIJIN_NOEXCEPT
|
||||
{
|
||||
if (this == &other)
|
||||
{
|
||||
@@ -85,7 +86,7 @@ public:
|
||||
return static_cast<TActual&>(*this);
|
||||
}
|
||||
|
||||
TActual& operator=(Base&& other) noexcept
|
||||
TActual& operator=(Base&& other) MIJIN_NOEXCEPT
|
||||
{
|
||||
if (this == &other)
|
||||
{
|
||||
@@ -95,22 +96,22 @@ public:
|
||||
handle_ = std::exchange(other.handle_, {});
|
||||
return static_cast<TActual&>(*this);
|
||||
}
|
||||
auto operator<=>(const Base&) const noexcept = default;
|
||||
operator bool() const noexcept { return static_cast<bool>(handle_); }
|
||||
bool operator!() const noexcept { return !static_cast<bool>(handle_); }
|
||||
auto operator<=>(const Base&) const MIJIN_NOEXCEPT = default;
|
||||
operator bool() const MIJIN_NOEXCEPT { return static_cast<bool>(handle_); }
|
||||
bool operator!() const MIJIN_NOEXCEPT { return !static_cast<bool>(handle_); }
|
||||
|
||||
[[nodiscard]]
|
||||
THandle getHandle() const noexcept { return handle_; }
|
||||
THandle getHandle() const MIJIN_NOEXCEPT { return handle_; }
|
||||
|
||||
[[nodiscard]]
|
||||
THandle releaseHandle() noexcept { return std::exchange(handle_, nullptr); }
|
||||
THandle releaseHandle() MIJIN_NOEXCEPT { return std::exchange(handle_, nullptr); }
|
||||
};
|
||||
|
||||
class X509Store : public Base<X509Store, X509_STORE*>
|
||||
{
|
||||
public:
|
||||
using Base::Base;
|
||||
Error create() noexcept
|
||||
Error create() MIJIN_NOEXCEPT
|
||||
{
|
||||
MIJIN_ASSERT(handle_ == nullptr, "X509 Store already created.");
|
||||
ERR_clear_error();
|
||||
@@ -122,7 +123,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
void free() noexcept
|
||||
void free() MIJIN_NOEXCEPT
|
||||
{
|
||||
if (handle_ != nullptr)
|
||||
{
|
||||
@@ -131,7 +132,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
Error loadFile(const char* file) const noexcept
|
||||
Error loadFile(const char* file) const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
if (!X509_STORE_load_file(handle_, file))
|
||||
@@ -141,7 +142,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
static void upReferences(X509_STORE* handle) noexcept
|
||||
static void upReferences(X509_STORE* handle) MIJIN_NOEXCEPT
|
||||
{
|
||||
X509_STORE_up_ref(handle);
|
||||
}
|
||||
@@ -150,7 +151,7 @@ public:
|
||||
class Context : public Base<Context, SSL_CTX*>
|
||||
{
|
||||
public:
|
||||
Error create(const SSL_METHOD* method) noexcept
|
||||
Error create(const SSL_METHOD* method) MIJIN_NOEXCEPT
|
||||
{
|
||||
MIJIN_ASSERT(handle_ == nullptr, "Context already created.");
|
||||
ERR_clear_error();
|
||||
@@ -162,7 +163,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
void free() noexcept
|
||||
void free() MIJIN_NOEXCEPT
|
||||
{
|
||||
if (handle_ == nullptr)
|
||||
{
|
||||
@@ -172,17 +173,17 @@ public:
|
||||
handle_ = nullptr;
|
||||
}
|
||||
|
||||
void setVerify(int mode, verify_callback_t callback = nullptr) const noexcept
|
||||
void setVerify(int mode, verify_callback_t callback = nullptr) const MIJIN_NOEXCEPT
|
||||
{
|
||||
SSL_CTX_set_verify(handle_, mode, callback);
|
||||
}
|
||||
|
||||
void setCertStore(X509Store store) const noexcept
|
||||
void setCertStore(X509Store store) const MIJIN_NOEXCEPT
|
||||
{
|
||||
SSL_CTX_set_cert_store(handle_, store.releaseHandle());
|
||||
}
|
||||
|
||||
Error setMinProtoVersion(int version) const noexcept
|
||||
Error setMinProtoVersion(int version) const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
if (!SSL_CTX_set_min_proto_version(handle_, version))
|
||||
@@ -192,7 +193,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
static void upReferences(SSL_CTX* handle) noexcept
|
||||
static void upReferences(SSL_CTX* handle) MIJIN_NOEXCEPT
|
||||
{
|
||||
SSL_CTX_up_ref(handle);
|
||||
}
|
||||
@@ -201,7 +202,7 @@ public:
|
||||
class Bio : public Base<Bio, BIO*>
|
||||
{
|
||||
public:
|
||||
Error createPair(Bio& otherBio, std::size_t writeBuf = 0, std::size_t otherWriteBuf = 0) noexcept
|
||||
Error createPair(Bio& otherBio, std::size_t writeBuf = 0, std::size_t otherWriteBuf = 0) MIJIN_NOEXCEPT
|
||||
{
|
||||
MIJIN_ASSERT(handle_ == nullptr, "Ssl already created.");
|
||||
MIJIN_ASSERT(otherBio.handle_ == nullptr, "Ssl already created.");
|
||||
@@ -213,7 +214,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
void free() noexcept
|
||||
void free() MIJIN_NOEXCEPT
|
||||
{
|
||||
if (handle_ == nullptr)
|
||||
{
|
||||
@@ -224,18 +225,18 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::size_t ctrlPending() const noexcept
|
||||
std::size_t ctrlPending() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return BIO_ctrl_pending(handle_);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::size_t ctrlWPending() const noexcept
|
||||
std::size_t ctrlWPending() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return BIO_ctrl_wpending(handle_);
|
||||
}
|
||||
|
||||
Result<int> write(const void* data, int length) const noexcept
|
||||
Result<int> write(const void* data, int length) const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
const int result = BIO_write(handle_, data, length);
|
||||
@@ -246,7 +247,7 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Result<int> read(void* data, int length) const noexcept
|
||||
Result<int> read(void* data, int length) const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
const int result = BIO_read(handle_, data, length);
|
||||
@@ -258,24 +259,24 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int getReadRequest() const noexcept
|
||||
int getReadRequest() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return BIO_get_read_request(handle_);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int getWriteGuarantee() const noexcept
|
||||
int getWriteGuarantee() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return BIO_get_write_guarantee(handle_);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int getWritePending() const noexcept
|
||||
int getWritePending() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return BIO_wpending(handle_);
|
||||
}
|
||||
|
||||
Error flush() const noexcept
|
||||
Error flush() const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
if (!BIO_flush(handle_))
|
||||
@@ -285,7 +286,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
static void upReferences(BIO* handle) noexcept
|
||||
static void upReferences(BIO* handle) MIJIN_NOEXCEPT
|
||||
{
|
||||
BIO_up_ref(handle);
|
||||
}
|
||||
@@ -294,7 +295,7 @@ public:
|
||||
class Ssl : public Base<Ssl, SSL*>
|
||||
{
|
||||
public:
|
||||
Error create(const Context& context) noexcept
|
||||
Error create(const Context& context) MIJIN_NOEXCEPT
|
||||
{
|
||||
MIJIN_ASSERT(handle_ == nullptr, "Ssl already created.");
|
||||
ERR_clear_error();
|
||||
@@ -306,7 +307,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
void free() noexcept
|
||||
void free() MIJIN_NOEXCEPT
|
||||
{
|
||||
if (handle_ == nullptr)
|
||||
{
|
||||
@@ -316,18 +317,18 @@ public:
|
||||
handle_ = nullptr;
|
||||
}
|
||||
|
||||
void setBio(Bio readBio, Bio writeBio) const noexcept
|
||||
void setBio(Bio readBio, Bio writeBio) const MIJIN_NOEXCEPT
|
||||
{
|
||||
SSL_set_bio(handle_, readBio.releaseHandle(), writeBio.releaseHandle());
|
||||
}
|
||||
|
||||
void setBio(Bio&& bio) const noexcept
|
||||
void setBio(Bio&& bio) const MIJIN_NOEXCEPT
|
||||
{
|
||||
BIO* bioHandle = bio.releaseHandle();
|
||||
SSL_set_bio(handle_, bioHandle, bioHandle);
|
||||
}
|
||||
|
||||
Error setTLSExtHostname(const char* hostname) const noexcept
|
||||
Error setTLSExtHostname(const char* hostname) const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
if (const int result = SSL_set_tlsext_host_name(handle_, hostname); result != 1)
|
||||
@@ -337,7 +338,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
Error setHost(const char* hostname) const noexcept
|
||||
Error setHost(const char* hostname) const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
if (const int result = SSL_set1_host(handle_, hostname); result != 1)
|
||||
@@ -347,7 +348,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
Error connect() const noexcept
|
||||
Error connect() const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
if (const int result = SSL_connect(handle_); result != 1)
|
||||
@@ -357,7 +358,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
Error shutdown() const noexcept
|
||||
Error shutdown() const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
if (const int result = SSL_shutdown(handle_); result != 1)
|
||||
@@ -372,12 +373,12 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
long getVerifyResult() const noexcept
|
||||
long getVerifyResult() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return SSL_get_verify_result(handle_);
|
||||
}
|
||||
|
||||
Result<int> write(const void* data, int length) const noexcept
|
||||
Result<int> write(const void* data, int length) const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
const int result = SSL_write(handle_, data, length);
|
||||
@@ -388,7 +389,7 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
Result<int> read(void* data, int length) const noexcept
|
||||
Result<int> read(void* data, int length) const MIJIN_NOEXCEPT
|
||||
{
|
||||
ERR_clear_error();
|
||||
const int result = SSL_read(handle_, data, length);
|
||||
@@ -400,18 +401,18 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
int pending() const noexcept
|
||||
int pending() const MIJIN_NOEXCEPT
|
||||
{
|
||||
return SSL_pending(handle_);
|
||||
}
|
||||
|
||||
static void upReferences(SSL* handle) noexcept
|
||||
static void upReferences(SSL* handle) MIJIN_NOEXCEPT
|
||||
{
|
||||
SSL_up_ref(handle);
|
||||
}
|
||||
};
|
||||
|
||||
Error Error::current(int sslError_) noexcept
|
||||
Error Error::current(int sslError_) MIJIN_NOEXCEPT
|
||||
{
|
||||
Error error = {
|
||||
.sslError = sslError_
|
||||
|
||||
Reference in New Issue
Block a user