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>
diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c
index 5be162f..24c859e 100644
--- a/programs/ssl/ssl_client2.c
+++ b/programs/ssl/ssl_client2.c
@@ -523,42 +523,6 @@
#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
*/
diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c
index dc33381..8f97541 100644
--- a/programs/ssl/ssl_server2.c
+++ b/programs/ssl/ssl_server2.c
@@ -623,44 +623,6 @@
#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
*/
diff --git a/programs/ssl/ssl_test_common_source.c b/programs/ssl/ssl_test_common_source.c
index d9e3607..35dfa60 100644
--- a/programs/ssl/ssl_test_common_source.c
+++ b/programs/ssl/ssl_test_common_source.c
@@ -303,3 +303,41 @@
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 */