mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 00:35:50 +01:00
58 lines
1.6 KiB
Plaintext
58 lines
1.6 KiB
Plaintext
/* BEGIN_HEADER */
|
|
#include "polarssl/base64.h"
|
|
#include "polarssl/pem.h"
|
|
#include "polarssl/des.h"
|
|
#include "polarssl/aes.h"
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_PEM_WRITE_C */
|
|
void pem_write_buffer( char *start, char *end, char *buf_str, char *result_str )
|
|
{
|
|
unsigned char buf[5000];
|
|
unsigned char *check_buf = NULL;
|
|
int ret;
|
|
size_t buf_len, olen = 0, olen2 = 0;
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
|
|
buf_len = unhexify( buf, buf_str );
|
|
|
|
ret = pem_write_buffer( start, end, buf, buf_len, NULL, 0, &olen );
|
|
TEST_ASSERT( ret == POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL );
|
|
|
|
check_buf = (unsigned char *) polarssl_malloc( olen );
|
|
TEST_ASSERT( check_buf != NULL );
|
|
|
|
memset( check_buf, 0, olen );
|
|
ret = pem_write_buffer( start, end, buf, buf_len, check_buf, olen, &olen2 );
|
|
|
|
TEST_ASSERT( olen2 <= olen );
|
|
TEST_ASSERT( olen > strlen( (char*) result_str ) );
|
|
TEST_ASSERT( ret == 0 );
|
|
TEST_ASSERT( strncmp( (char *) check_buf, (char *) result_str, olen ) == 0 );
|
|
|
|
exit:
|
|
polarssl_free( check_buf );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_PEM_PARSE_C:POLARSSL_AES_C:POLARSSL_DES_C:POLARSSL_MD5_C:POLARSSL_CIPHER_MODE_CBC */
|
|
void pem_read_buffer( char *header, char *footer, char *data, char *pwd,
|
|
int res )
|
|
{
|
|
pem_context ctx;
|
|
int ret;
|
|
size_t use_len = 0;
|
|
size_t pwd_len = strlen( pwd );
|
|
|
|
pem_init( &ctx );
|
|
|
|
ret = pem_read_buffer( &ctx, header, footer, (const unsigned char *)data,
|
|
(unsigned char *)pwd, pwd_len, &use_len );
|
|
TEST_ASSERT( ret == res );
|
|
|
|
exit:
|
|
pem_free( &ctx );
|
|
}
|
|
/* END_CASE */
|