Change macro name to WS_RETURN_CODE and add more comments.

This commit is contained in:
TakayukiMatsuo
2021-03-08 11:57:36 +09:00
parent bbf1284112
commit feeb0ceb96
3 changed files with 23 additions and 16 deletions

View File

@ -6916,7 +6916,7 @@ int wolfSSL_CTX_load_verify_locations(WOLFSSL_CTX* ctx, const char* file,
int ret = wolfSSL_CTX_load_verify_locations_ex(ctx, file, path, int ret = wolfSSL_CTX_load_verify_locations_ex(ctx, file, path,
WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS); WOLFSSL_LOAD_VERIFY_DEFAULT_FLAGS);
return RETURN_CODE(ret,WOLFSSL_FAILURE); return WS_RETURN_CODE(ret,WOLFSSL_FAILURE);
} }
@ -24409,15 +24409,15 @@ int wolfSSL_X509_LOOKUP_load_file(WOLFSSL_X509_LOOKUP* lookup,
const char* footer = NULL; const char* footer = NULL;
if (type != X509_FILETYPE_PEM) if (type != X509_FILETYPE_PEM)
return RETURN_CODE(BAD_FUNC_ARG,WOLFSSL_FAILURE); return WS_RETURN_CODE(BAD_FUNC_ARG,WOLFSSL_FAILURE);
fp = XFOPEN(file, "rb"); fp = XFOPEN(file, "rb");
if (fp == XBADFILE) if (fp == XBADFILE)
return RETURN_CODE(BAD_FUNC_ARG,WOLFSSL_FAILURE); return WS_RETURN_CODE(BAD_FUNC_ARG,WOLFSSL_FAILURE);
if(XFSEEK(fp, 0, XSEEK_END) != 0) { if(XFSEEK(fp, 0, XSEEK_END) != 0) {
XFCLOSE(fp); XFCLOSE(fp);
return RETURN_CODE(WOLFSSL_BAD_FILE,WOLFSSL_FAILURE); return WS_RETURN_CODE(WOLFSSL_BAD_FILE,WOLFSSL_FAILURE);
} }
sz = XFTELL(fp); sz = XFTELL(fp);
XREWIND(fp); XREWIND(fp);
@ -24487,12 +24487,12 @@ end:
if (pem != NULL) if (pem != NULL)
XFREE(pem, 0, DYNAMIC_TYPE_PEM); XFREE(pem, 0, DYNAMIC_TYPE_PEM);
XFCLOSE(fp); XFCLOSE(fp);
return RETURN_CODE(ret,WOLFSSL_FAILURE); return WS_RETURN_CODE(ret,WOLFSSL_FAILURE);
#else #else
(void)lookup; (void)lookup;
(void)file; (void)file;
(void)type; (void)type;
return RETURN_CODE(WOLFSSL_FAILURE,WOLFSSL_FAILURE); return WS_RETURN_CODE(WOLFSSL_FAILURE,WOLFSSL_FAILURE);
#endif #endif
} }

View File

@ -954,19 +954,19 @@ static void test_wolfSSL_CTX_load_verify_locations(void)
/* invalid ca file */ /* invalid ca file */
AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, bogusFile, NULL), AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, bogusFile, NULL),
RETURN_CODE(WOLFSSL_BAD_FILE,WOLFSSL_FAILURE)); WS_RETURN_CODE(WOLFSSL_BAD_FILE,WOLFSSL_FAILURE));
#if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS) #if !defined(NO_WOLFSSL_DIR) && !defined(WOLFSSL_TIRTOS)
/* invalid path */ /* invalid path */
AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, bogusFile), AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, NULL, bogusFile),
RETURN_CODE(BAD_PATH_ERROR,WOLFSSL_FAILURE)); WS_RETURN_CODE(BAD_PATH_ERROR,WOLFSSL_FAILURE));
#endif #endif
/* load ca cert */ /* load ca cert */
#ifdef NO_RSA #ifdef NO_RSA
AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL), AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL),
RETURN_CODE(ASN_UNKNOWN_OID_E,WOLFSSL_FAILURE)); WS_RETURN_CODE(ASN_UNKNOWN_OID_E,WOLFSSL_FAILURE));
#else /* Skip the following test without RSA certs. */ #else /* Skip the following test without RSA certs. */
AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL), WOLFSSL_SUCCESS); AssertIntEQ(wolfSSL_CTX_load_verify_locations(ctx, caCertFile, NULL), WOLFSSL_SUCCESS);

View File

@ -674,19 +674,26 @@ enum AlertLevel {
alert_fatal = 2 alert_fatal = 2
}; };
/* RETURN_CODE macro /* WS_RETURN_CODE macro
* Some OpenSSL APIs specify "0" as the return value when an error occurs. * Some OpenSSL APIs specify "0" as the return value when an error occurs.
* However, some corresponding wolfSSL APIs(eg. * However, some corresponding wolfSSL APIs return negative values. Such
* wolfSSL_CTX_load_verify_locations) return negative values. Such functions * functions should use this macro to fill this gap. Users who want them
* should use this macro to fill this gap. Users who want them to return * to return the same return value as OpenSSL can define
* the same return value as OpenSSL can define WOLFSSL_ERR_CODE_OPENSSL. * WOLFSSL_ERR_CODE_OPENSSL.
* Give item1 a variable that contains the potentially negative
* wolfSSL-defined return value or the return value itself, and
* give item2 the openSSL-defined return value.
* Note that this macro replaces only negative return values with the * Note that this macro replaces only negative return values with the
* specified value. * specified value.
* Since wolfSSL 4.7.0, the following functions use this macro:
* - wolfSSL_CTX_load_verify_locations
* - wolfSSL_X509_LOOKUP_load_file
*/ */
#if defined(WOLFSSL_ERROR_CODE_OPENSSL) #if defined(WOLFSSL_ERROR_CODE_OPENSSL)
#define RETURN_CODE(w,o) ((w < 0)?o:w) #define WS_RETURN_CODE(item1,item2) \
((item1 < 0) ? item2 : item1)
#else #else
#define RETURN_CODE(w,o) (w) #define WS_RETURN_CODE(item1,item2) (item1)
#endif #endif
/* Maximum master key length (SECRET_LEN) */ /* Maximum master key length (SECRET_LEN) */