From 213c12c4f12101b560d532416788914b9f67399a Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 22 Nov 2024 14:27:35 +0100 Subject: [PATCH] Change some assertions to exceptions --- common/rdr/AESInStream.cxx | 4 +++- common/rdr/AESOutStream.cxx | 6 ++++-- common/rfb/CSecurityRSAAES.cxx | 4 +++- common/rfb/SSecurityRSAAES.cxx | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/common/rdr/AESInStream.cxx b/common/rdr/AESInStream.cxx index a4890899..b10a214a 100644 --- a/common/rdr/AESInStream.cxx +++ b/common/rdr/AESInStream.cxx @@ -22,6 +22,8 @@ #include +#include + #include #ifdef HAVE_NETTLE @@ -36,7 +38,7 @@ AESInStream::AESInStream(InStream* _in, const uint8_t* key, else if (keySize == 256) EAX_SET_KEY(&eaxCtx256, aes256_set_encrypt_key, aes256_encrypt, key); else - assert(!"incorrect key size"); + throw std::out_of_range("Incorrect key size"); } AESInStream::~AESInStream() {} diff --git a/common/rdr/AESOutStream.cxx b/common/rdr/AESOutStream.cxx index fcb3e37a..1ec38b56 100644 --- a/common/rdr/AESOutStream.cxx +++ b/common/rdr/AESOutStream.cxx @@ -21,7 +21,9 @@ #endif #include -#include + +#include + #include #ifdef HAVE_NETTLE @@ -39,7 +41,7 @@ AESOutStream::AESOutStream(OutStream* _out, const uint8_t* key, else if (keySize == 256) EAX_SET_KEY(&eaxCtx256, aes256_set_encrypt_key, aes256_encrypt, key); else - assert(!"incorrect key size"); + throw std::out_of_range("Incorrect key size"); } AESOutStream::~AESOutStream() diff --git a/common/rfb/CSecurityRSAAES.cxx b/common/rfb/CSecurityRSAAES.cxx index 416eaa2d..56e1d702 100644 --- a/common/rfb/CSecurityRSAAES.cxx +++ b/common/rfb/CSecurityRSAAES.cxx @@ -126,7 +126,9 @@ bool CSecurityRSAAES::processMsg() writeCredentials(); return true; } - assert(!"unreachable"); + + throw std::logic_error("Invalid state"); + return false; } diff --git a/common/rfb/SSecurityRSAAES.cxx b/common/rfb/SSecurityRSAAES.cxx index 1e5f2384..46b66ca9 100644 --- a/common/rfb/SSecurityRSAAES.cxx +++ b/common/rfb/SSecurityRSAAES.cxx @@ -278,7 +278,9 @@ bool SSecurityRSAAES::processMsg() verifyPass(); return true; } - assert(!"unreachable"); + + throw std::logic_error("Invalid state"); + return false; } -- 2.39.5