Fix ret code in pk_encrypt.c

This commit is contained in:
Andres Amaya Garcia 2018-04-29 22:19:26 +01:00
parent f47c9c11d1
commit 52898179cf

View file

@ -29,9 +29,12 @@
#include "mbedtls/platform.h"
#else
#include <stdio.h>
#define mbedtls_fprintf fprintf
#define mbedtls_printf printf
#endif
#include <stdlib.h>
#define mbedtls_fprintf fprintf
#define mbedtls_printf printf
#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
#endif /* MBEDTLS_PLATFORM_C */
#if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_PK_PARSE_C) && \
defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_FS_IO) && \
@ -59,7 +62,8 @@ int main( void )
int main( int argc, char *argv[] )
{
FILE *f;
int ret;
int ret = 1;
int exit_code = MBEDTLS_EXIT_FAILURE;
size_t i, olen = 0;
mbedtls_pk_context pk;
mbedtls_entropy_context entropy;
@ -68,7 +72,6 @@ int main( int argc, char *argv[] )
unsigned char buf[512];
const char *pers = "mbedtls_pk_encrypt";
ret = 1;
mbedtls_ctr_drbg_init( &ctr_drbg );
if( argc != 3 )
@ -132,7 +135,6 @@ int main( int argc, char *argv[] )
*/
if( ( f = fopen( "result-enc.txt", "wb+" ) ) == NULL )
{
ret = 1;
mbedtls_printf( " failed\n ! Could not create %s\n\n", "result-enc.txt" );
goto exit;
}
@ -145,12 +147,14 @@ int main( int argc, char *argv[] )
mbedtls_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
exit_code = MBEDTLS_EXIT_SUCCESS;
exit:
mbedtls_ctr_drbg_free( &ctr_drbg );
mbedtls_entropy_free( &entropy );
#if defined(MBEDTLS_ERROR_C)
if( ret != 0 )
if( exit_code != MBEDTLS_EXIT_SUCCESS )
{
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
mbedtls_printf( " ! Last error was: %s\n", buf );
@ -162,7 +166,7 @@ exit:
fflush( stdout ); getchar();
#endif
return( ret );
return( exit_code );
}
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_PK_PARSE_C && MBEDTLS_ENTROPY_C &&
MBEDTLS_FS_IO && MBEDTLS_CTR_DRBG_C */