add ERR_lib_error_string

This commit is contained in:
Hideki Miyazaki
2021-07-21 10:31:00 +09:00
parent af98e64b88
commit b76d44dad9
4 changed files with 71 additions and 0 deletions

View File

@@ -19879,6 +19879,33 @@ const char* wolfSSL_ERR_func_error_string(unsigned long e)
return ""; return "";
} }
/* return library name
* @param e error code
* @return text library name,
* if there is no suitable library found, returns empty string
*/
const char* wolfSSL_ERR_lib_error_string(unsigned long e)
{
int libe = 0;
(void)libe;
(void)e;
#if defined(OPENSSL_EXTRA)
libe = wolfSSL_ERR_GET_LIB(e);
switch (libe) {
case ERR_LIB_PEM:
return "wolfSSL PEM routines";
case ERR_LIB_EVP:
return "wolfSSL digital envelope routines";
default:
return "";
}
#else
return "";
#endif
}
void SetErrorString(int error, char* str) void SetErrorString(int error, char* str)
{ {
XSTRNCPY(str, wolfSSL_ERR_reason_error_string(error), WOLFSSL_MAX_ERROR_SZ); XSTRNCPY(str, wolfSSL_ERR_reason_error_string(error), WOLFSSL_MAX_ERROR_SZ);

View File

@@ -45730,6 +45730,47 @@ static void test_wolfSSL_DH_get0_pqg(void)
#endif /* OPENSSL_EXTRA && !NO_DH */ #endif /* OPENSSL_EXTRA && !NO_DH */
} }
static void test_wolfSSL_ERR_strings()
{
const char* err1 = "unsupported cipher suite";
const char* err2 = "wolfSSL PEM routines";
const char* err = NULL;
(void)err;
(void)err1;
(void)err2;
#if !defined(NO_ERROR_STRINGS)
printf(testingFmt, "test_wolfSSL_ERR_strings");
#if defined(OPENSSL_EXTRA)
err = ERR_reason_error_string(UNSUPPORTED_SUITE);
AssertTrue(err != NULL);
AssertIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
err = ERR_func_error_string(UNSUPPORTED_SUITE);
AssertTrue(err != NULL);
AssertIntEQ((*err == '\0'), 1);
err = ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD);
AssertTrue(err != NULL);
AssertIntEQ(XSTRNCMP(err, err2, XSTRLEN(err2)), 0);
#else
err = wolfSSL_ERR_reason_error_string(UNSUPPORTED_SUITE);
AssertTrue(err != NULL);
AssertIntEQ(XSTRNCMP(err, err1, XSTRLEN(err1)), 0);
err = wolfSSL_ERR_func_error_string(UNSUPPORTED_SUITE);
AssertTrue(err != NULL);
AssertIntEQ((*err == '\0'), 1);
err = wolfSSL_ERR_lib_error_string(PEM_R_PROBLEMS_GETTING_PASSWORD);
AssertTrue(err != NULL);
AssertIntEQ((*err == ('\0')), 1);
#endif
printf(resultFmt, passed);
#endif
}
/*----------------------------------------------------------------------------* /*----------------------------------------------------------------------------*
| Main | Main
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@@ -45750,6 +45791,7 @@ void ApiTest(void)
(!defined(NO_RSA) || defined(HAVE_ECC)) (!defined(NO_RSA) || defined(HAVE_ECC))
test_for_double_Free(); test_for_double_Free();
#endif #endif
test_wolfSSL_ERR_strings();
test_wolfSSL_CTX_use_certificate_file(); test_wolfSSL_CTX_use_certificate_file();
AssertIntEQ(test_wolfSSL_CTX_use_certificate_buffer(), WOLFSSL_SUCCESS); AssertIntEQ(test_wolfSSL_CTX_use_certificate_buffer(), WOLFSSL_SUCCESS);
test_wolfSSL_CTX_use_PrivateKey_file(); test_wolfSSL_CTX_use_PrivateKey_file();

View File

@@ -917,6 +917,7 @@ wolfSSL_X509_STORE_set_verify_cb((WOLFSSL_X509_STORE *)(s), (WOLFSSL_X509_STORE_
#define ERR_error_string_n wolfSSL_ERR_error_string_n #define ERR_error_string_n wolfSSL_ERR_error_string_n
#define ERR_reason_error_string wolfSSL_ERR_reason_error_string #define ERR_reason_error_string wolfSSL_ERR_reason_error_string
#define ERR_func_error_string wolfSSL_ERR_func_error_string #define ERR_func_error_string wolfSSL_ERR_func_error_string
#define ERR_lib_error_string wolfSSL_ERR_lib_error_string
#define ERR_load_BIO_strings wolfSSL_ERR_load_BIO_strings #define ERR_load_BIO_strings wolfSSL_ERR_load_BIO_strings
#ifndef WOLFCRYPT_ONLY #ifndef WOLFCRYPT_ONLY

View File

@@ -1272,6 +1272,7 @@ WOLFSSL_API void wolfSSL_ERR_error_string_n(unsigned long e, char* buf,
unsigned long sz); unsigned long sz);
WOLFSSL_API const char* wolfSSL_ERR_reason_error_string(unsigned long); WOLFSSL_API const char* wolfSSL_ERR_reason_error_string(unsigned long);
WOLFSSL_API const char* wolfSSL_ERR_func_error_string(unsigned long); WOLFSSL_API const char* wolfSSL_ERR_func_error_string(unsigned long);
WOLFSSL_API const char* wolfSSL_ERR_lib_error_string(unsigned long);
/* extras */ /* extras */