/* BEGIN_HEADER */
#include "mbedtls/asn1write.h"

#define GUARD_LEN 4
#define GUARD_VAL 0x2a
/* END_HEADER */

/* BEGIN_DEPENDENCIES
 * depends_on:MBEDTLS_ASN1_WRITE_C
 * END_DEPENDENCIES
 */

/* BEGIN_CASE */
void mbedtls_asn1_write_octet_string( char *hex_str, char *hex_asn1,
                              int buf_len, int result )
{
    int ret;
    unsigned char buf[150];
    unsigned char str[150] = { 0 };
    unsigned char asn1[150] = { 0 };
    size_t str_len, asn1_len, i;
    unsigned char *p;

    memset( buf, GUARD_VAL, sizeof( buf ) );

    str_len = unhexify( str, hex_str );
    asn1_len = unhexify( asn1, hex_asn1 );

    p = buf + GUARD_LEN + buf_len;

    ret = mbedtls_asn1_write_octet_string( &p, buf + GUARD_LEN, str, str_len );

    /* Check for buffer overwrite on both sides */
    for( i = 0; i < GUARD_LEN; i++ )
    {
        TEST_ASSERT( buf[i] == GUARD_VAL );
        TEST_ASSERT( buf[GUARD_LEN + buf_len + i] == GUARD_VAL );
    }

    if( result >= 0 )
    {
        TEST_ASSERT( (size_t) ret == asn1_len );
        TEST_ASSERT( p + asn1_len == buf + GUARD_LEN + buf_len );

        TEST_ASSERT( memcmp( p, asn1, asn1_len ) == 0 );
    }
}
/* END_CASE */

/* BEGIN_CASE */
void mbedtls_asn1_write_ia5_string( char *str, char *hex_asn1,
                            int buf_len, int result )
{
    int ret;
    unsigned char buf[150];
    unsigned char asn1[150] = { 0 };
    size_t str_len, asn1_len, i;
    unsigned char *p;

    memset( buf, GUARD_VAL, sizeof( buf ) );

    str_len = strlen( str );
    asn1_len = unhexify( asn1, hex_asn1 );

    p = buf + GUARD_LEN + buf_len;

    ret = mbedtls_asn1_write_ia5_string( &p, buf + GUARD_LEN, str, str_len );

    /* Check for buffer overwrite on both sides */
    for( i = 0; i < GUARD_LEN; i++ )
    {
        TEST_ASSERT( buf[i] == GUARD_VAL );
        TEST_ASSERT( buf[GUARD_LEN + buf_len + i] == GUARD_VAL );
    }

    if( result >= 0 )
    {
        TEST_ASSERT( (size_t) ret == asn1_len );
        TEST_ASSERT( p + asn1_len == buf + GUARD_LEN + buf_len );

        TEST_ASSERT( memcmp( p, asn1, asn1_len ) == 0 );
    }
}
/* END_CASE */
