mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibCrypto: Print all descriptive OpenSSL errors
The code was printing one error message only, but multiple can be generated in one call. Additionally, using this builtin produces a much more descriptive output.
This commit is contained in:
parent
c580763743
commit
de6f77e7e3
Notes:
github-actions[bot]
2025-01-27 11:26:35 +00:00
Author: https://github.com/devgianlu Commit: https://github.com/LadybirdBrowser/ladybird/commit/de6f77e7e3e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3374 Reviewed-by: https://github.com/alimpfard ✅
2 changed files with 9 additions and 10 deletions
|
@ -13,14 +13,17 @@
|
|||
|
||||
namespace Crypto {
|
||||
|
||||
static int openssl_print_errors(char const* str, size_t len, [[maybe_unused]] void* u)
|
||||
{
|
||||
dbgln("{}", StringView { str, len });
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define OPENSSL_TRY_PTR(...) \
|
||||
({ \
|
||||
auto* _temporary_result = (__VA_ARGS__); \
|
||||
if (!_temporary_result) [[unlikely]] { \
|
||||
auto err = ERR_get_error(); \
|
||||
VERIFY(err); \
|
||||
auto* err_message = ERR_error_string(err, nullptr); \
|
||||
dbgln("OpenSSL error: {}", err_message); \
|
||||
ERR_print_errors_cb(openssl_print_errors, nullptr); \
|
||||
return Error::from_string_literal(#__VA_ARGS__ " failed"); \
|
||||
} \
|
||||
_temporary_result; \
|
||||
|
@ -30,10 +33,7 @@ namespace Crypto {
|
|||
({ \
|
||||
auto _temporary_result = (__VA_ARGS__); \
|
||||
if (_temporary_result != 1) [[unlikely]] { \
|
||||
auto err = ERR_get_error(); \
|
||||
VERIFY(err); \
|
||||
auto* err_message = ERR_error_string(err, nullptr); \
|
||||
dbgln("OpenSSL error: {}", err_message); \
|
||||
ERR_print_errors_cb(openssl_print_errors, nullptr); \
|
||||
return Error::from_string_literal(#__VA_ARGS__ " failed"); \
|
||||
} \
|
||||
_temporary_result; \
|
||||
|
|
|
@ -14,8 +14,7 @@ typedef struct evp_md_ctx_st EVP_MD_CTX;
|
|||
typedef struct evp_pkey_st EVP_PKEY;
|
||||
typedef struct evp_pkey_ctx_st EVP_PKEY_CTX;
|
||||
|
||||
long unsigned int ERR_get_error();
|
||||
char* ERR_error_string(long unsigned int, char*);
|
||||
void ERR_print_errors_cb(int (*cb)(char const* str, size_t len, void* u), void* u);
|
||||
|
||||
EVP_MD_CTX* EVP_MD_CTX_new();
|
||||
void EVP_MD_CTX_free(EVP_MD_CTX*);
|
||||
|
|
Loading…
Add table
Reference in a new issue