Fix ret code in pk_encrypt.c
This commit is contained in:
parent
81982c84d4
commit
141b4f4526
1 changed files with 12 additions and 8 deletions
|
@ -29,9 +29,12 @@
|
||||||
#include "mbedtls/platform.h"
|
#include "mbedtls/platform.h"
|
||||||
#else
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#define mbedtls_fprintf fprintf
|
#define mbedtls_fprintf fprintf
|
||||||
#define mbedtls_printf printf
|
#define mbedtls_printf printf
|
||||||
#endif
|
#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) && \
|
#if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_PK_PARSE_C) && \
|
||||||
defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_FS_IO) && \
|
defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_FS_IO) && \
|
||||||
|
@ -59,7 +62,8 @@ int main( void )
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int ret;
|
int ret = 1;
|
||||||
|
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||||
size_t i, olen = 0;
|
size_t i, olen = 0;
|
||||||
mbedtls_pk_context pk;
|
mbedtls_pk_context pk;
|
||||||
mbedtls_entropy_context entropy;
|
mbedtls_entropy_context entropy;
|
||||||
|
@ -68,7 +72,6 @@ int main( int argc, char *argv[] )
|
||||||
unsigned char buf[512];
|
unsigned char buf[512];
|
||||||
const char *pers = "mbedtls_pk_encrypt";
|
const char *pers = "mbedtls_pk_encrypt";
|
||||||
|
|
||||||
ret = 1;
|
|
||||||
mbedtls_ctr_drbg_init( &ctr_drbg );
|
mbedtls_ctr_drbg_init( &ctr_drbg );
|
||||||
|
|
||||||
if( argc != 3 )
|
if( argc != 3 )
|
||||||
|
@ -132,7 +135,6 @@ int main( int argc, char *argv[] )
|
||||||
*/
|
*/
|
||||||
if( ( f = fopen( "result-enc.txt", "wb+" ) ) == NULL )
|
if( ( f = fopen( "result-enc.txt", "wb+" ) ) == NULL )
|
||||||
{
|
{
|
||||||
ret = 1;
|
|
||||||
mbedtls_printf( " failed\n ! Could not create %s\n\n", "result-enc.txt" );
|
mbedtls_printf( " failed\n ! Could not create %s\n\n", "result-enc.txt" );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -145,12 +147,14 @@ int main( int argc, char *argv[] )
|
||||||
|
|
||||||
mbedtls_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
mbedtls_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" );
|
||||||
|
|
||||||
|
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ctr_drbg_free( &ctr_drbg );
|
mbedtls_ctr_drbg_free( &ctr_drbg );
|
||||||
mbedtls_entropy_free( &entropy );
|
mbedtls_entropy_free( &entropy );
|
||||||
|
|
||||||
#if defined(MBEDTLS_ERROR_C)
|
#if defined(MBEDTLS_ERROR_C)
|
||||||
if( ret != 0 )
|
if( exit_code != MBEDTLS_EXIT_SUCCESS )
|
||||||
{
|
{
|
||||||
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
|
mbedtls_strerror( ret, (char *) buf, sizeof(buf) );
|
||||||
mbedtls_printf( " ! Last error was: %s\n", buf );
|
mbedtls_printf( " ! Last error was: %s\n", buf );
|
||||||
|
@ -162,7 +166,7 @@ exit:
|
||||||
fflush( stdout ); getchar();
|
fflush( stdout ); getchar();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return( ret );
|
return( exit_code );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_PK_PARSE_C && MBEDTLS_ENTROPY_C &&
|
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_PK_PARSE_C && MBEDTLS_ENTROPY_C &&
|
||||||
MBEDTLS_FS_IO && MBEDTLS_CTR_DRBG_C */
|
MBEDTLS_FS_IO && MBEDTLS_CTR_DRBG_C */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue