1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-07 06:42:56 +03:00

Use pk_load_file() in X509

Saves a bit of ROM. X509 depends on PK anyway.
This commit is contained in:
Manuel Pégourié-Gonnard
2014-11-21 09:49:43 +01:00
parent 2457fa0915
commit 9439f93ea4
7 changed files with 14 additions and 51 deletions

View File

@@ -71,7 +71,7 @@ static void polarssl_zeroize( void *v, size_t n ) {
/*
* Load all data from a file into a given buffer.
*/
static int load_file( const char *path, unsigned char **buf, size_t *n )
int pk_load_file( const char *path, unsigned char **buf, size_t *n )
{
FILE *f;
long size;
@@ -120,7 +120,7 @@ int pk_parse_keyfile( pk_context *ctx,
size_t n;
unsigned char *buf;
if( ( ret = load_file( path, &buf, &n ) ) != 0 )
if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
if( pwd == NULL )
@@ -144,7 +144,7 @@ int pk_parse_public_keyfile( pk_context *ctx, const char *path )
size_t n;
unsigned char *buf;
if( ( ret = load_file( path, &buf, &n ) ) != 0 )
if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
ret = pk_parse_public_key( ctx, buf, n );

View File

@@ -636,50 +636,6 @@ int x509_get_ext( unsigned char **p, const unsigned char *end,
return( 0 );
}
#if defined(POLARSSL_FS_IO)
/*
* Load all data from a file into a given buffer.
*/
int x509_load_file( const char *path, unsigned char **buf, size_t *n )
{
FILE *f;
long size;
if( ( f = fopen( path, "rb" ) ) == NULL )
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
fseek( f, 0, SEEK_END );
if( ( size = ftell( f ) ) == -1 )
{
fclose( f );
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
}
fseek( f, 0, SEEK_SET );
*n = (size_t) size;
if( *n + 1 == 0 ||
( *buf = (unsigned char *) polarssl_malloc( *n + 1 ) ) == NULL )
{
fclose( f );
return( POLARSSL_ERR_X509_MALLOC_FAILED );
}
if( fread( *buf, 1, *n, f ) != *n )
{
fclose( f );
polarssl_free( *buf );
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
}
fclose( f );
(*buf)[*n] = '\0';
return( 0 );
}
#endif /* POLARSSL_FS_IO */
#if defined(_MSC_VER) && !defined snprintf && !defined(EFIX64) && \
!defined(EFI32)
#include <stdarg.h>

View File

@@ -549,7 +549,7 @@ int x509_crl_parse_file( x509_crl *chain, const char *path )
size_t n;
unsigned char *buf;
if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
ret = x509_crl_parse( chain, buf, n );

View File

@@ -953,7 +953,7 @@ int x509_crt_parse_file( x509_crt *chain, const char *path )
size_t n;
unsigned char *buf;
if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
ret = x509_crt_parse( chain, buf, n );

View File

@@ -310,7 +310,7 @@ int x509_csr_parse_file( x509_csr *csr, const char *path )
size_t n;
unsigned char *buf;
if( ( ret = x509_load_file( path, &buf, &n ) ) != 0 )
if( ( ret = pk_load_file( path, &buf, &n ) ) != 0 )
return( ret );
ret = x509_csr_parse( csr, buf, n );