mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 15:15:43 +01:00
ce11699cf2
Apparently fread() writes some junk after the contents of the file. Don't look at it.
75 lines
1.8 KiB
Plaintext
75 lines
1.8 KiB
Plaintext
/* BEGIN_HEADER */
|
|
#include "polarssl/pk.h"
|
|
#include "polarssl/pem.h"
|
|
#include "polarssl/oid.h"
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
* depends_on:POLARSSL_PK_WRITE_C:POLARSSL_BIGNUM_C:POLARSSL_FS_IO
|
|
* END_DEPENDENCIES
|
|
*/
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_PEM_WRITE_C */
|
|
void pk_write_pubkey_check( char *key_file )
|
|
{
|
|
pk_context key;
|
|
unsigned char buf[5000];
|
|
unsigned char check_buf[5000];
|
|
int ret;
|
|
FILE *f;
|
|
size_t ilen;
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
memset( check_buf, 0, sizeof( check_buf ) );
|
|
|
|
pk_init( &key );
|
|
TEST_ASSERT( pk_parse_public_keyfile( &key, key_file ) == 0 );
|
|
|
|
ret = pk_write_pubkey_pem( &key, buf, sizeof( buf ));
|
|
TEST_ASSERT( ret == 0 );
|
|
|
|
f = fopen( key_file, "r" );
|
|
TEST_ASSERT( f != NULL );
|
|
ilen = fread( check_buf, 1, sizeof( check_buf ), f );
|
|
fclose( f );
|
|
|
|
TEST_ASSERT( ilen == strlen( (char *) buf ) );
|
|
TEST_ASSERT( memcmp( (char *) buf, (char *) check_buf, ilen ) == 0 );
|
|
|
|
exit:
|
|
pk_free( &key );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_PEM_WRITE_C */
|
|
void pk_write_key_check( char *key_file )
|
|
{
|
|
pk_context key;
|
|
unsigned char buf[5000];
|
|
unsigned char check_buf[5000];
|
|
int ret;
|
|
FILE *f;
|
|
size_t ilen;
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
memset( check_buf, 0, sizeof( check_buf ) );
|
|
|
|
pk_init( &key );
|
|
TEST_ASSERT( pk_parse_keyfile( &key, key_file, NULL ) == 0 );
|
|
|
|
ret = pk_write_key_pem( &key, buf, sizeof( buf ));
|
|
TEST_ASSERT( ret == 0 );
|
|
|
|
f = fopen( key_file, "r" );
|
|
TEST_ASSERT( f != NULL );
|
|
ilen = fread( check_buf, 1, sizeof( check_buf ), f );
|
|
fclose( f );
|
|
|
|
TEST_ASSERT( ilen == strlen( (char *) buf ) );
|
|
TEST_ASSERT( memcmp( (char *) buf, (char *) check_buf, ilen ) == 0 );
|
|
|
|
exit:
|
|
pk_free( &key );
|
|
}
|
|
/* END_CASE */
|