Use pk_load_file() in X509
Saves a bit of ROM. X509 depends on PK anyway.
diff --git a/library/pkparse.c b/library/pkparse.c
index 29217a2..6cfab8b 100644
--- a/library/pkparse.c
+++ b/library/pkparse.c
@@ -71,7 +71,7 @@
/*
* 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 @@
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 @@
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 );
diff --git a/library/x509.c b/library/x509.c
index 89ba763..78cf02d 100644
--- a/library/x509.c
+++ b/library/x509.c
@@ -636,50 +636,6 @@
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>
diff --git a/library/x509_crl.c b/library/x509_crl.c
index c8101b5..a0bf9f4 100644
--- a/library/x509_crl.c
+++ b/library/x509_crl.c
@@ -549,7 +549,7 @@
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 );
diff --git a/library/x509_crt.c b/library/x509_crt.c
index 4d20889..aba9c69 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -953,7 +953,7 @@
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 );
diff --git a/library/x509_csr.c b/library/x509_csr.c
index 0b4f771..5831121 100644
--- a/library/x509_csr.c
+++ b/library/x509_csr.c
@@ -310,7 +310,7 @@
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 );