test_suite_pem.function 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* BEGIN_HEADER */
  2. #include "mbedtls/base64.h"
  3. #include "mbedtls/pem.h"
  4. #include "mbedtls/des.h"
  5. #include "mbedtls/aes.h"
  6. /* END_HEADER */
  7. /* BEGIN_CASE depends_on:MBEDTLS_PEM_WRITE_C */
  8. void mbedtls_pem_write_buffer( char * start, char * end, data_t * buf,
  9. char * result_str )
  10. {
  11. unsigned char *check_buf = NULL;
  12. int ret;
  13. size_t olen = 0, olen2 = 0;
  14. ret = mbedtls_pem_write_buffer( start, end, buf->x, buf->len, NULL, 0, &olen );
  15. TEST_ASSERT( ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
  16. check_buf = (unsigned char *) mbedtls_calloc( 1, olen );
  17. TEST_ASSERT( check_buf != NULL );
  18. ret = mbedtls_pem_write_buffer( start, end, buf->x, buf->len, check_buf, olen, &olen2 );
  19. TEST_ASSERT( olen2 <= olen );
  20. TEST_ASSERT( olen > strlen( (char*) result_str ) );
  21. TEST_ASSERT( ret == 0 );
  22. TEST_ASSERT( strncmp( (char *) check_buf, (char *) result_str, olen ) == 0 );
  23. exit:
  24. mbedtls_free( check_buf );
  25. }
  26. /* END_CASE */
  27. /* BEGIN_CASE depends_on:MBEDTLS_PEM_PARSE_C:MBEDTLS_AES_C:MBEDTLS_DES_C:MBEDTLS_MD5_C:MBEDTLS_CIPHER_MODE_CBC */
  28. void mbedtls_pem_read_buffer( char *header, char *footer, char *data,
  29. char *pwd, int res )
  30. {
  31. mbedtls_pem_context ctx;
  32. int ret;
  33. size_t use_len = 0;
  34. size_t pwd_len = strlen( pwd );
  35. mbedtls_pem_init( &ctx );
  36. ret = mbedtls_pem_read_buffer( &ctx, header, footer, (unsigned char *)data,
  37. (unsigned char *)pwd, pwd_len, &use_len );
  38. TEST_ASSERT( ret == res );
  39. exit:
  40. mbedtls_pem_free( &ctx );
  41. }
  42. /* END_CASE */