mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-05-04 19:42:17 +00:00
modify library/debug.c to use polarssl_snprintf
This commit is contained in:
parent
fac657fd52
commit
2387c7d105
|
@ -44,6 +44,12 @@
|
||||||
#endif
|
#endif
|
||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
|
#if defined(POLARSSL_PLATFORM_C)
|
||||||
|
#include "polarssl/platform.h"
|
||||||
|
#else
|
||||||
|
#define polarssl_snprintf snprintf
|
||||||
|
#endif
|
||||||
|
|
||||||
static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE;
|
static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE;
|
||||||
static int debug_threshold = 0;
|
static int debug_threshold = 0;
|
||||||
|
|
||||||
|
@ -86,7 +92,7 @@ void debug_print_msg( const ssl_context *ssl, int level,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text );
|
polarssl_snprintf( str, maxlen, "%s(%04d): %s\n", file, line, text );
|
||||||
str[maxlen] = '\0';
|
str[maxlen] = '\0';
|
||||||
ssl->f_dbg( ssl->p_dbg, level, str );
|
ssl->f_dbg( ssl->p_dbg, level, str );
|
||||||
}
|
}
|
||||||
|
@ -103,9 +109,9 @@ void debug_print_ret( const ssl_context *ssl, int level,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
|
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
|
||||||
|
|
||||||
snprintf( str + idx, maxlen - idx, "%s() returned %d (-0x%04x)\n",
|
polarssl_snprintf( str + idx, maxlen - idx, "%s() returned %d (-0x%04x)\n",
|
||||||
text, ret, -ret );
|
text, ret, -ret );
|
||||||
|
|
||||||
str[maxlen] = '\0';
|
str[maxlen] = '\0';
|
||||||
|
@ -124,9 +130,9 @@ void debug_print_buf( const ssl_context *ssl, int level,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
|
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
|
||||||
|
|
||||||
snprintf( str + idx, maxlen - idx, "dumping '%s' (%u bytes)\n",
|
polarssl_snprintf( str + idx, maxlen - idx, "dumping '%s' (%u bytes)\n",
|
||||||
text, (unsigned int) len );
|
text, (unsigned int) len );
|
||||||
|
|
||||||
str[maxlen] = '\0';
|
str[maxlen] = '\0';
|
||||||
|
@ -143,7 +149,7 @@ void debug_print_buf( const ssl_context *ssl, int level,
|
||||||
{
|
{
|
||||||
if( i > 0 )
|
if( i > 0 )
|
||||||
{
|
{
|
||||||
snprintf( str + idx, maxlen - idx, " %s\n", txt );
|
polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
|
||||||
ssl->f_dbg( ssl->p_dbg, level, str );
|
ssl->f_dbg( ssl->p_dbg, level, str );
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
|
@ -151,14 +157,14 @@ void debug_print_buf( const ssl_context *ssl, int level,
|
||||||
}
|
}
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
|
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
|
||||||
|
|
||||||
idx += snprintf( str + idx, maxlen - idx, "%04x: ",
|
idx += polarssl_snprintf( str + idx, maxlen - idx, "%04x: ",
|
||||||
(unsigned int) i );
|
(unsigned int) i );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
idx += snprintf( str + idx, maxlen - idx, " %02x",
|
idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x",
|
||||||
(unsigned int) buf[i] );
|
(unsigned int) buf[i] );
|
||||||
txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
|
txt[i % 16] = ( buf[i] > 31 && buf[i] < 127 ) ? buf[i] : '.' ;
|
||||||
}
|
}
|
||||||
|
@ -166,9 +172,9 @@ void debug_print_buf( const ssl_context *ssl, int level,
|
||||||
if( len > 0 )
|
if( len > 0 )
|
||||||
{
|
{
|
||||||
for( /* i = i */; i % 16 != 0; i++ )
|
for( /* i = i */; i % 16 != 0; i++ )
|
||||||
idx += snprintf( str + idx, maxlen - idx, " " );
|
idx += polarssl_snprintf( str + idx, maxlen - idx, " " );
|
||||||
|
|
||||||
snprintf( str + idx, maxlen - idx, " %s\n", txt );
|
polarssl_snprintf( str + idx, maxlen - idx, " %s\n", txt );
|
||||||
ssl->f_dbg( ssl->p_dbg, level, str );
|
ssl->f_dbg( ssl->p_dbg, level, str );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,11 +190,11 @@ void debug_print_ecp( const ssl_context *ssl, int level,
|
||||||
if( ssl->f_dbg == NULL || level > debug_threshold )
|
if( ssl->f_dbg == NULL || level > debug_threshold )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
snprintf( str, maxlen, "%s(X)", text );
|
polarssl_snprintf( str, maxlen, "%s(X)", text );
|
||||||
str[maxlen] = '\0';
|
str[maxlen] = '\0';
|
||||||
debug_print_mpi( ssl, level, file, line, str, &X->X );
|
debug_print_mpi( ssl, level, file, line, str, &X->X );
|
||||||
|
|
||||||
snprintf( str, maxlen, "%s(Y)", text );
|
polarssl_snprintf( str, maxlen, "%s(Y)", text );
|
||||||
str[maxlen] = '\0';
|
str[maxlen] = '\0';
|
||||||
debug_print_mpi( ssl, level, file, line, str, &X->Y );
|
debug_print_mpi( ssl, level, file, line, str, &X->Y );
|
||||||
}
|
}
|
||||||
|
@ -215,9 +221,9 @@ void debug_print_mpi( const ssl_context *ssl, int level,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
|
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
|
||||||
|
|
||||||
snprintf( str + idx, maxlen - idx, "value of '%s' (%d bits) is:\n",
|
polarssl_snprintf( str + idx, maxlen - idx, "value of '%s' (%d bits) is:\n",
|
||||||
text, (int) ( ( n * ( sizeof(t_uint) << 3 ) ) + j + 1 ) );
|
text, (int) ( ( n * ( sizeof(t_uint) << 3 ) ) + j + 1 ) );
|
||||||
|
|
||||||
str[maxlen] = '\0';
|
str[maxlen] = '\0';
|
||||||
|
@ -240,16 +246,16 @@ void debug_print_mpi( const ssl_context *ssl, int level,
|
||||||
{
|
{
|
||||||
if( j > 0 )
|
if( j > 0 )
|
||||||
{
|
{
|
||||||
snprintf( str + idx, maxlen - idx, "\n" );
|
polarssl_snprintf( str + idx, maxlen - idx, "\n" );
|
||||||
ssl->f_dbg( ssl->p_dbg, level, str );
|
ssl->f_dbg( ssl->p_dbg, level, str );
|
||||||
idx = 0;
|
idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
|
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
|
||||||
}
|
}
|
||||||
|
|
||||||
idx += snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
|
idx += polarssl_snprintf( str + idx, maxlen - idx, " %02x", (unsigned int)
|
||||||
( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
|
( X->p[i - 1] >> ( k << 3 ) ) & 0xFF );
|
||||||
|
|
||||||
j++;
|
j++;
|
||||||
|
@ -261,13 +267,13 @@ void debug_print_mpi( const ssl_context *ssl, int level,
|
||||||
{
|
{
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
{
|
{
|
||||||
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
|
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
|
||||||
|
|
||||||
}
|
}
|
||||||
idx += snprintf( str + idx, maxlen - idx, " 00" );
|
idx += polarssl_snprintf( str + idx, maxlen - idx, " 00" );
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf( str + idx, maxlen - idx, "\n" );
|
polarssl_snprintf( str + idx, maxlen - idx, "\n" );
|
||||||
ssl->f_dbg( ssl->p_dbg, level, str );
|
ssl->f_dbg( ssl->p_dbg, level, str );
|
||||||
}
|
}
|
||||||
#endif /* POLARSSL_BIGNUM_C */
|
#endif /* POLARSSL_BIGNUM_C */
|
||||||
|
@ -294,7 +300,7 @@ static void debug_print_pk( const ssl_context *ssl, int level,
|
||||||
if( items[i].type == POLARSSL_PK_DEBUG_NONE )
|
if( items[i].type == POLARSSL_PK_DEBUG_NONE )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
|
polarssl_snprintf( name, sizeof( name ), "%s%s", text, items[i].name );
|
||||||
name[sizeof( name ) - 1] = '\0';
|
name[sizeof( name ) - 1] = '\0';
|
||||||
|
|
||||||
if( items[i].type == POLARSSL_PK_DEBUG_MPI )
|
if( items[i].type == POLARSSL_PK_DEBUG_MPI )
|
||||||
|
@ -321,7 +327,7 @@ void debug_print_crt( const ssl_context *ssl, int level,
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
{
|
{
|
||||||
snprintf( prefix, maxlen, "%s(%04d): ", file, line );
|
polarssl_snprintf( prefix, maxlen, "%s(%04d): ", file, line );
|
||||||
prefix[maxlen] = '\0';
|
prefix[maxlen] = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -335,9 +341,9 @@ void debug_print_crt( const ssl_context *ssl, int level,
|
||||||
x509_crt_info( buf, sizeof( buf ) - 1, prefix, crt );
|
x509_crt_info( buf, sizeof( buf ) - 1, prefix, crt );
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
idx = snprintf( str, maxlen, "%s(%04d): ", file, line );
|
idx = polarssl_snprintf( str, maxlen, "%s(%04d): ", file, line );
|
||||||
|
|
||||||
snprintf( str + idx, maxlen - idx, "%s #%d:\n%s",
|
polarssl_snprintf( str + idx, maxlen - idx, "%s #%d:\n%s",
|
||||||
text, ++i, buf );
|
text, ++i, buf );
|
||||||
|
|
||||||
str[maxlen] = '\0';
|
str[maxlen] = '\0';
|
||||||
|
|
Loading…
Reference in a new issue