Move x509_crt_verify_info to ssl_test_common_source.c

This function was introduced before ssl_test_common_source.c and so the
function is replicated in both ssl_client2.c and ssl_server2.c. Move
the function to ssl_test_common_source.c to avoid duplication.

Signed-off-by: Chris Jones <christopher.jones@arm.com>
This commit is contained in:
Chris Jones 2021-04-27 14:50:43 +01:00
parent 856db5f722
commit e383fa65d7
3 changed files with 38 additions and 74 deletions

View file

@ -523,42 +523,6 @@ struct options
#if defined(MBEDTLS_X509_CRT_PARSE_C)
static unsigned char peer_crt_info[1024];
#if !defined(MBEDTLS_X509_REMOVE_INFO)
int x509_crt_verify_info( char *buf, size_t size, const char *prefix,
uint32_t flags )
{
return( mbedtls_x509_crt_verify_info( buf, size, prefix, flags ) );
}
#else /* !MBEDTLS_X509_REMOVE_INFO */
int x509_crt_verify_info( char *buf, size_t size, const char *prefix,
uint32_t flags )
{
int ret;
char *p = buf;
size_t n = size;
#define X509_CRT_ERROR_INFO( err, err_str, info ) \
if( ( flags & err ) != 0 ) \
{ \
ret = mbedtls_snprintf( p, n, "%s%s\n", prefix, info ); \
MBEDTLS_X509_SAFE_SNPRINTF; \
flags ^= err; \
}
MBEDTLS_X509_CRT_ERROR_INFO_LIST
#undef X509_CRT_ERROR_INFO
if( flags != 0 )
{
ret = mbedtls_snprintf( p, n, "%sUnknown reason "
"(this should not happen)\n", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
}
return( (int) ( size - n ) );
}
#endif /* MBEDTLS_X509_REMOVE_INFO */
/*
* Enabled if debug_level > 1 in code below
*/

View file

@ -623,44 +623,6 @@ struct options
#include "ssl_test_common_source.c"
#if defined(MBEDTLS_X509_CRT_PARSE_C)
#if !defined(MBEDTLS_X509_REMOVE_INFO)
int x509_crt_verify_info( char *buf, size_t size, const char *prefix,
uint32_t flags )
{
return( mbedtls_x509_crt_verify_info( buf, size, prefix, flags ) );
}
#else /* !MBEDTLS_X509_REMOVE_INFO */
int x509_crt_verify_info( char *buf, size_t size, const char *prefix,
uint32_t flags )
{
int ret;
char *p = buf;
size_t n = size;
#define X509_CRT_ERROR_INFO( err, err_str, info ) \
if( ( flags & err ) != 0 ) \
{ \
ret = mbedtls_snprintf( p, n, "%s%s\n", prefix, info ); \
MBEDTLS_X509_SAFE_SNPRINTF; \
flags ^= err; \
}
MBEDTLS_X509_CRT_ERROR_INFO_LIST
#undef X509_CRT_ERROR_INFO
if( flags != 0 )
{
ret = mbedtls_snprintf( p, n, "%sUnknown reason "
"(this should not happen)\n", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
}
return( (int) ( size - n ) );
}
#endif /* MBEDTLS_X509_REMOVE_INFO */
#endif /* MBEDTLS_X509_CRT_PARSE_C */
/*
* Return authmode from string, or -1 on error
*/

View file

@ -303,3 +303,41 @@ int ssl_sig_hashes_for_test[] = {
MBEDTLS_MD_NONE
};
#endif /* MBEDTLS_X509_CRT_PARSE_C */
#if defined(MBEDTLS_X509_CRT_PARSE_C)
#if !defined(MBEDTLS_X509_REMOVE_INFO)
/** Functionally equivalent to mbedtls_x509_crt_verify_info, see that function
* for more info.
*/
int x509_crt_verify_info( char *buf, size_t size, const char *prefix,
uint32_t flags )
{
return( mbedtls_x509_crt_verify_info( buf, size, prefix, flags ) );
#else /* !MBEDTLS_X509_REMOVE_INFO */
int ret;
char *p = buf;
size_t n = size;
#define X509_CRT_ERROR_INFO( err, err_str, info ) \
if( ( flags & err ) != 0 ) \
{ \
ret = mbedtls_snprintf( p, n, "%s%s\n", prefix, info ); \
MBEDTLS_X509_SAFE_SNPRINTF; \
flags ^= err; \
}
MBEDTLS_X509_CRT_ERROR_INFO_LIST
#undef X509_CRT_ERROR_INFO
if( flags != 0 )
{
ret = mbedtls_snprintf( p, n, "%sUnknown reason "
"(this should not happen)\n", prefix );
MBEDTLS_X509_SAFE_SNPRINTF;
}
return( (int) ( size - n ) );
#endif /* MBEDTLS_X509_REMOVE_INFO */
}
#endif /* MBEDTLS_X509_CRT_PARSE_C */