From a90fee4e125a136cffba66c36bcb3e0d48907318 Mon Sep 17 00:00:00 2001 From: Lukasz Pawelczyk Date: Tue, 28 Apr 2020 17:33:44 +0200 Subject: [PATCH] Add all debug functions to debug.h Add translate_error that was not available. Move others from internal. Include debug.h in internal.h. The reason for that is to make it easier to test debug functions by only including debug.h. internal.h is not includable by C++ code. Both those headers are internal and nothing changes in terms of public API. Change-Id: Ica6886c9253d45a5f131a36b457044132daee14a --- src/debug.c | 1 + src/debug.h | 29 ++++++++++++++++++++++++++++- src/internal.h | 24 +++++------------------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/debug.c b/src/debug.c index e6e2d06..e23214b 100644 --- a/src/debug.c +++ b/src/debug.c @@ -34,6 +34,7 @@ #include "internal.h" #include "debug.h" + // TODO any better idea than to use __thread? static __thread yaca_error_cb error_cb = NULL; static bool error_strings_loaded = false; diff --git a/src/debug.h b/src/debug.h index e6b5902..8a268fd 100644 --- a/src/debug.h +++ b/src/debug.h @@ -24,18 +24,45 @@ #ifndef YACA_DEBUG_H #define YACA_DEBUG_H + +#include + +#include + + #ifdef __cplusplus extern "C" { #endif typedef void (*yaca_error_cb)(const char*); - void yaca_debug_set_error_cb(yaca_error_cb cb); +const char *yaca_debug_translate_error(yaca_error_e err); + +#define ERROR_CLEAR() ERR_clear_error() + +void error_dump(const char *file, int line, const char *function, int code); +#define ERROR_DUMP(code) error_dump(__FILE__, __LINE__, __func__, (code)) + +/** + * Function responsible for translating the openssl error to yaca error and + * clearing/dumping the openssl error queue. Use only after openssl function + * failure. + * + * The function checks only first error in the queue. If the function doesn't + * find any error in openssl queue or is not able to translate it, it will + * return YACA_ERROR_INTERNAL and dump openssl errors if any. If the + * translation succeeds the function will clear the error queue and return the + * result of translation. + */ +int error_handle(const char *file, int line, const char *function); +#define ERROR_HANDLE() error_handle(__FILE__, __LINE__, __func__) + #ifdef __cplusplus } /* extern */ #endif + #endif /* YACA_DEBUG_H */ diff --git a/src/internal.h b/src/internal.h index c6b933c..a020d03 100644 --- a/src/internal.h +++ b/src/internal.h @@ -24,17 +24,20 @@ #ifndef YACA_INTERNAL_H #define YACA_INTERNAL_H + #include #include #include -#include #include #include #include #include +#include "debug.h" + + #define API __attribute__ ((visibility("default"))) #define UNUSED __attribute__((unused)) @@ -161,24 +164,7 @@ struct yaca_key_evp_s *key_get_evp(const yaca_key_h key); yaca_key_h key_copy(const yaca_key_h key); -void error_dump(const char *file, int line, const char *function, int code); -#define ERROR_DUMP(code) error_dump(__FILE__, __LINE__, __func__, (code)) -#define ERROR_CLEAR() ERR_clear_error() - -/** - * Function responsible for translating the openssl error to yaca error and - * clearing/dumping the openssl error queue. Use only after openssl function - * failure. - * - * The function checks only first error in the queue. If the function doesn't - * find any error in openssl queue or is not able to translate it, it will - * return YACA_ERROR_INTERNAL and dump openssl errors if any. If the - * translation succeeds the function will clear the error queue and return the - * result of translation. - */ -int error_handle(const char *file, int line, const char *function); -#define ERROR_HANDLE() error_handle(__FILE__, __LINE__, __func__) - int rsa_padding2openssl(yaca_padding_e padding); + #endif /* YACA_INTERNAL_H */ -- 2.7.4