Use platform layer in programs for consistency.

This commit is contained in:
Rich Evans 2015-01-19 14:26:37 +00:00 committed by Paul Bakker
parent e94e6e5b9c
commit f90016aade
48 changed files with 1572 additions and 1145 deletions

View file

@ -26,6 +26,15 @@
#include POLARSSL_CONFIG_FILE
#endif
#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf printf
#define polarssl_fprintf fprintf
#define polarssl_malloc malloc
#define polarssl_free free
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@ -41,7 +50,7 @@ int main( int argc, char *argv[] )
((void) argc);
((void) argv);
printf("POLARSSL_BIGNUM_C and/or "
polarssl_printf("POLARSSL_BIGNUM_C and/or "
"POLARSSL_PK_PARSE_C and/or POLARSSL_FS_IO not defined.\n");
return( 0 );
}
@ -94,7 +103,7 @@ int main( int argc, char *argv[] )
if( argc == 0 )
{
usage:
printf( USAGE );
polarssl_printf( USAGE );
goto exit;
}
@ -133,7 +142,7 @@ int main( int argc, char *argv[] )
{
if( strlen( opt.password ) && strlen( opt.password_file ) )
{
printf( "Error: cannot have both password and password_file\n" );
polarssl_printf( "Error: cannot have both password and password_file\n" );
goto usage;
}
@ -141,16 +150,16 @@ int main( int argc, char *argv[] )
{
FILE *f;
printf( "\n . Loading the password file ..." );
polarssl_printf( "\n . Loading the password file ..." );
if( ( f = fopen( opt.password_file, "rb" ) ) == NULL )
{
printf( " failed\n ! fopen returned NULL\n" );
polarssl_printf( " failed\n ! fopen returned NULL\n" );
goto exit;
}
if( fgets( buf, sizeof(buf), f ) == NULL )
{
fclose( f );
printf( "Error: fgets() failed to retrieve password\n" );
polarssl_printf( "Error: fgets() failed to retrieve password\n" );
goto exit;
}
fclose( f );
@ -164,23 +173,23 @@ int main( int argc, char *argv[] )
/*
* 1.1. Load the key
*/
printf( "\n . Loading the private key ..." );
polarssl_printf( "\n . Loading the private key ..." );
fflush( stdout );
ret = pk_parse_keyfile( &pk, opt.filename, opt.password );
if( ret != 0 )
{
printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret );
polarssl_printf( " failed\n ! pk_parse_keyfile returned -0x%04x\n", -ret );
goto exit;
}
printf( " ok\n" );
polarssl_printf( " ok\n" );
/*
* 1.2 Print the key
*/
printf( " . Key information ...\n" );
polarssl_printf( " . Key information ...\n" );
#if defined(POLARSSL_RSA_C)
if( pk_get_type( &pk ) == POLARSSL_PK_RSA )
{
@ -208,7 +217,7 @@ int main( int argc, char *argv[] )
else
#endif
{
printf("Do not know how to print key information for this type\n" );
polarssl_printf("Do not know how to print key information for this type\n" );
goto exit;
}
}
@ -217,20 +226,20 @@ int main( int argc, char *argv[] )
/*
* 1.1. Load the key
*/
printf( "\n . Loading the public key ..." );
polarssl_printf( "\n . Loading the public key ..." );
fflush( stdout );
ret = pk_parse_public_keyfile( &pk, opt.filename );
if( ret != 0 )
{
printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
polarssl_printf( " failed\n ! pk_parse_public_keyfile returned -0x%04x\n", -ret );
goto exit;
}
printf( " ok\n" );
polarssl_printf( " ok\n" );
printf( " . Key information ...\n" );
polarssl_printf( " . Key information ...\n" );
#if defined(POLARSSL_RSA_C)
if( pk_get_type( &pk ) == POLARSSL_PK_RSA )
{
@ -251,7 +260,7 @@ int main( int argc, char *argv[] )
else
#endif
{
printf("Do not know how to print key information for this type\n" );
polarssl_printf("Do not know how to print key information for this type\n" );
goto exit;
}
}
@ -262,13 +271,13 @@ exit:
#if defined(POLARSSL_ERROR_C)
polarssl_strerror( ret, buf, sizeof(buf) );
printf( " ! Last error was: %s\n", buf );
polarssl_printf( " ! Last error was: %s\n", buf );
#endif
pk_free( &pk );
#if defined(_WIN32)
printf( " + Press Enter to exit this program.\n" );
polarssl_printf( " + Press Enter to exit this program.\n" );
fflush( stdout ); getchar();
#endif