Reduce code size when mbedtls_x509_*_info() unused

Introduce MBEDTLS_X509_INFO to indicate the availability of the
mbedtls_x509_*_info() function and closely related APIs. When this is
not defined, also omit name and description from
mbedtls_oid_descriptor_t, and omit OID arrays, macros, and types that
are entirely unused. This saves several KB of code space.

Change-Id: I056312613379890e0d70e1d08c34171287c0aa17
This commit is contained in:
Peter Kolbus 2018-12-11 13:55:56 -06:00 committed by Hanno Becker
parent 1abb159e90
commit dc470ae8af
27 changed files with 273 additions and 150 deletions

View file

@ -488,19 +488,28 @@ static int my_send( void *ctx, const unsigned char *buf, size_t len )
static int my_verify( void *data, mbedtls_x509_crt *crt,
int depth, uint32_t *flags )
{
#if defined(MBEDTLS_X509_INFO)
char buf[1024];
#endif
((void) data);
#if defined(MBEDTLS_X509_INFO)
mbedtls_printf( "\nVerify requested for (Depth %d):\n", depth );
mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
mbedtls_printf( "%s", buf );
#else
((void) crt);
((void) depth);
#endif
if ( ( *flags ) == 0 )
mbedtls_printf( " This certificate has no flags\n" );
else
{
#if defined(MBEDTLS_X509_INFO)
mbedtls_x509_crt_verify_info( buf, sizeof( buf ), " ! ", *flags );
mbedtls_printf( "%s\n", buf );
#endif
}
return( 0 );
@ -1976,14 +1985,18 @@ int main( int argc, char *argv[] )
if( ( flags = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 )
{
#if defined(MBEDTLS_X509_INFO)
char vrfy_buf[512];
#endif
mbedtls_printf( " failed\n" );
#if defined(MBEDTLS_X509_INFO)
mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ),
" ! ", flags );
mbedtls_printf( "%s\n", vrfy_buf );
#endif
}
else
mbedtls_printf( " ok\n" );