mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-25 07:18:49 +00:00
115 lines
2.8 KiB
Text
115 lines
2.8 KiB
Text
/* BEGIN_HEADER */
|
|
#include <polarssl/debug.h>
|
|
|
|
struct buffer_data
|
|
{
|
|
char buf[2000];
|
|
char *ptr;
|
|
};
|
|
|
|
void string_debug(void *data, int level, const char *str)
|
|
{
|
|
struct buffer_data *buffer = (struct buffer_data *) data;
|
|
((void) level);
|
|
|
|
memcpy(buffer->ptr, str, strlen(str));
|
|
buffer->ptr += strlen(str);
|
|
}
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
* depends_on:POLARSSL_DEBUG_C:POLARSSL_SSL_TLS_C
|
|
* END_DEPENDENCIES
|
|
*/
|
|
|
|
/* BEGIN_CASE */
|
|
void debug_print_ret( char *file, int line, char *text, int value,
|
|
char *result_str )
|
|
{
|
|
ssl_context ssl;
|
|
struct buffer_data buffer;
|
|
|
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
|
memset( buffer.buf, 0, 2000 );
|
|
buffer.ptr = buffer.buf;
|
|
|
|
ssl_set_dbg(&ssl, string_debug, &buffer);
|
|
|
|
debug_print_ret( &ssl, 0, file, line, text, value);
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE */
|
|
void debug_print_buf( char *file, int line, char *text, char *data_string,
|
|
char *result_str )
|
|
{
|
|
unsigned char data[10000];
|
|
ssl_context ssl;
|
|
struct buffer_data buffer;
|
|
size_t data_len;
|
|
|
|
memset( &data, 0, sizeof( data ) );
|
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
|
memset( buffer.buf, 0, 2000 );
|
|
buffer.ptr = buffer.buf;
|
|
|
|
data_len = unhexify( data, data_string );
|
|
|
|
ssl_set_dbg(&ssl, string_debug, &buffer);
|
|
|
|
debug_print_buf( &ssl, 0, file, line, text, data, data_len );
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */
|
|
void debug_print_crt( char *crt_file, char *file, int line, char *prefix,
|
|
char *result_str )
|
|
{
|
|
x509_crt crt;
|
|
ssl_context ssl;
|
|
struct buffer_data buffer;
|
|
|
|
x509_crt_init( &crt );
|
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
|
memset( buffer.buf, 0, 2000 );
|
|
buffer.ptr = buffer.buf;
|
|
|
|
ssl_set_dbg(&ssl, string_debug, &buffer);
|
|
|
|
TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
|
|
debug_print_crt( &ssl, 0, file, line, prefix, &crt);
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
|
|
x509_crt_free( &crt );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_BIGNUM_C */
|
|
void debug_print_mpi( int radix, char *value, char *file, int line,
|
|
char *prefix, char *result_str )
|
|
{
|
|
ssl_context ssl;
|
|
struct buffer_data buffer;
|
|
mpi val;
|
|
|
|
mpi_init( &val );
|
|
|
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
|
memset( buffer.buf, 0, 2000 );
|
|
buffer.ptr = buffer.buf;
|
|
|
|
TEST_ASSERT( mpi_read_string( &val, radix, value ) == 0 );
|
|
ssl_set_dbg(&ssl, string_debug, &buffer);
|
|
|
|
debug_print_mpi( &ssl, 0, file, line, prefix, &val);
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
|
|
mpi_free( &val );
|
|
}
|
|
/* END_CASE */
|