mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2026-01-08 07:28:58 +01:00
Use platform layer in programs for consistency.
This commit is contained in:
parent
e94e6e5b9c
commit
f90016aade
48 changed files with 1572 additions and 1145 deletions
|
|
@ -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>
|
||||
|
|
@ -40,7 +49,7 @@ int main( int argc, char *argv[] )
|
|||
((void) argc);
|
||||
((void) argv);
|
||||
|
||||
printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO not defined.\n" );
|
||||
polarssl_printf( "POLARSSL_PK_WRITE_C and/or POLARSSL_FS_IO not defined.\n" );
|
||||
return( 0 );
|
||||
}
|
||||
#else
|
||||
|
|
@ -201,7 +210,7 @@ int main( int argc, char *argv[] )
|
|||
{
|
||||
usage:
|
||||
ret = 1;
|
||||
printf( USAGE );
|
||||
polarssl_printf( USAGE );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -258,13 +267,13 @@ int main( int argc, char *argv[] )
|
|||
|
||||
if( opt.mode == MODE_NONE && opt.output_mode != OUTPUT_MODE_NONE )
|
||||
{
|
||||
printf( "\nCannot output a key without reading one.\n");
|
||||
polarssl_printf( "\nCannot output a key without reading one.\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( opt.mode == MODE_PUBLIC && opt.output_mode == OUTPUT_MODE_PRIVATE )
|
||||
{
|
||||
printf( "\nCannot output a private key from a public key.\n");
|
||||
polarssl_printf( "\nCannot output a private key from a public key.\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
@ -273,7 +282,7 @@ 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( &key, opt.filename, NULL );
|
||||
|
|
@ -281,16 +290,16 @@ int main( int argc, char *argv[] )
|
|||
if( ret != 0 )
|
||||
{
|
||||
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||
printf( " failed\n ! pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf );
|
||||
polarssl_printf( " failed\n ! pk_parse_keyfile returned -0x%04x - %s\n\n", -ret, buf );
|
||||
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( &key ) == POLARSSL_PK_RSA )
|
||||
|
|
@ -318,7 +327,7 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
else
|
||||
#endif
|
||||
printf("key type not supported yet\n");
|
||||
polarssl_printf("key type not supported yet\n");
|
||||
|
||||
}
|
||||
else if( opt.mode == MODE_PUBLIC )
|
||||
|
|
@ -326,7 +335,7 @@ 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( &key, opt.filename );
|
||||
|
|
@ -334,16 +343,16 @@ int main( int argc, char *argv[] )
|
|||
if( ret != 0 )
|
||||
{
|
||||
polarssl_strerror( ret, (char *) buf, sizeof(buf) );
|
||||
printf( " failed\n ! pk_parse_public_key returned -0x%04x - %s\n\n", -ret, buf );
|
||||
polarssl_printf( " failed\n ! pk_parse_public_key returned -0x%04x - %s\n\n", -ret, buf );
|
||||
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( &key ) == POLARSSL_PK_RSA )
|
||||
|
|
@ -364,7 +373,7 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
else
|
||||
#endif
|
||||
printf("key type not supported yet\n");
|
||||
polarssl_printf("key type not supported yet\n");
|
||||
}
|
||||
else
|
||||
goto usage;
|
||||
|
|
@ -384,16 +393,16 @@ exit:
|
|||
{
|
||||
#ifdef POLARSSL_ERROR_C
|
||||
polarssl_strerror( ret, buf, sizeof( buf ) );
|
||||
printf( " - %s\n", buf );
|
||||
polarssl_printf( " - %s\n", buf );
|
||||
#else
|
||||
printf("\n");
|
||||
polarssl_printf("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
pk_free( &key );
|
||||
|
||||
#if defined(_WIN32)
|
||||
printf( " + Press Enter to exit this program.\n" );
|
||||
polarssl_printf( " + Press Enter to exit this program.\n" );
|
||||
fflush( stdout ); getchar();
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue