Adding test and dox for ERR_print_errors_cb

This commit is contained in:
Eric Blankenhorn 2020-02-13 16:58:06 -06:00
parent 936312f77e
commit 95f973a5be
3 changed files with 71 additions and 1 deletions

View File

@ -4881,6 +4881,35 @@ WOLFSSL_API long wolfSSL_get_verify_result(const WOLFSSL *ssl);
*/
WOLFSSL_API void wolfSSL_ERR_print_errors_fp(FILE*, int err);
/*!
\ingroup Debug
\brief This function uses the provided callback to handle error reporting.
The callback function is executed for each error line. The string, length,
and userdata are passed into the callback parameters.
\return none No returns.
\param cb the callback function.
\param u userdata to pass into the callback function.
_Example_
\code
int error_cb(const char *str, size_t len, void *u)
{ fprintf((FILE*)u, "%-*.*s\n", (int)len, (int)len, str); return 0; }
...
FILE* fp = ...
wolfSSL_ERR_print_errors_cb(error_cb, fp);
\endcode
\sa wolfSSL_get_error
\sa wolfSSL_ERR_error_string
\sa wolfSSL_ERR_error_string_n
\sa wolfSSL_load_error_strings
*/
WOLFSSL_API void wolfSSL_ERR_print_errors_cb (
int (*cb)(const char *str, size_t len, void *u), void *u);
/*!
\brief The function sets the client_psk_cb member of the
WOLFSSL_CTX structure.

View File

@ -23229,6 +23229,41 @@ static void test_wolfSSL_ERR_print_errors(void)
#endif
}
#if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
defined(DEBUG_WOLFSSL)
static int test_wolfSSL_error_cb(const char *str, size_t len, void *u)
{
wolfSSL_BIO_write((BIO*)u, str, len);
return 0;
}
#endif
static void test_wolfSSL_ERR_print_errors_cb(void)
{
#if !defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && \
defined(DEBUG_WOLFSSL)
BIO* bio;
char buf[1024];
printf(testingFmt, "wolfSSL_ERR_print_errors_cb()");
AssertNotNull(bio = BIO_new(BIO_s_mem()));
ERR_clear_error(); /* clear out any error nodes */
ERR_put_error(0,SYS_F_ACCEPT, -173, "ssl.c", 0);
ERR_put_error(0,SYS_F_BIND, -275, "asn.c", 100);
ERR_print_errors_cb(test_wolfSSL_error_cb, bio);
AssertIntEQ(BIO_gets(bio, buf, sizeof(buf)), 108);
AssertIntEQ(XSTRNCMP("wolfSSL error occurred, error = 173 line:0 file:ssl.c",
buf, 53), 0);
AssertIntEQ(XSTRNCMP("wolfSSL error occurred, error = 275 line:100 file:asn.c",
buf + 53, 55), 0);
AssertIntEQ(BIO_gets(bio, buf, sizeof(buf)), 0);
BIO_free(bio);
printf(resultFmt, passed);
#endif
}
static void test_wolfSSL_HMAC(void)
{
@ -30644,6 +30679,7 @@ void ApiTest(void)
#if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER)
test_wolfSSL_ERR_peek_last_error_line();
#endif
test_wolfSSL_ERR_print_errors_cb();
test_wolfSSL_set_options();
test_wolfSSL_sk_SSL_CIPHER();
test_wolfSSL_X509_STORE_CTX();

View File

@ -798,6 +798,11 @@ void wc_ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
{
WOLFSSL_ENTER("wc_ERR_print_errors_cb");
if (cb == NULL) {
/* Invalid param */
return;
}
if (wc_LockMutex(&debug_mutex) != 0)
{
WOLFSSL_MSG("Lock debug mutex failed");
@ -830,7 +835,7 @@ void wc_ERR_print_errors_fp(XFILE fp)
WOLFSSL_ENTER("wc_ERR_print_errors_fp");
/* Send all errors to the wc_ERR_dump_to_file function */
wc_ERR_print_errors_cb(wc_ERR_dump_to_file,fp);
wc_ERR_print_errors_cb(wc_ERR_dump_to_file, fp);
}
#endif /* !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM) */