Add tests for asn1_write_ia5_string()

This commit is contained in:
Manuel Pégourié-Gonnard 2014-05-29 17:16:45 +02:00
parent 36178ffb87
commit c22bb4994c
2 changed files with 54 additions and 0 deletions

View file

@ -30,3 +30,21 @@ asn1_write_octet_string:"000102030405060708090A0B0C0D0E0F000102030405060708090A0
ASN.1 Write Octet String #9 (l = 128, buffer too small for string)
asn1_write_octet_string:"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F":"":127:POLARSSL_ERR_ASN1_BUF_TOO_SMALL
ASN.1 Write IA5 String #0 (Empty string)
asn1_write_ia5_string:"":"1600":2:2
ASN.1 Write IA5 String #1 (Large buffer)
asn1_write_ia5_string:"ABC":"1603414243":10:5
ASN.1 Write IA5 String #2 (Buffer just fits)
asn1_write_ia5_string:"ABC":"1603414243":5:5
ASN.1 Write IA5 String #3 (Buffer too small for tag)
asn1_write_ia5_string:"ABC":"":4:POLARSSL_ERR_ASN1_BUF_TOO_SMALL
ASN.1 Write IA5 String #4 (Buffer too small for len)
asn1_write_ia5_string:"ABC":"":3:POLARSSL_ERR_ASN1_BUF_TOO_SMALL
ASN.1 Write IA5 String #5 (Buffer too small for string)
asn1_write_ia5_string:"ABC":"":2:POLARSSL_ERR_ASN1_BUF_TOO_SMALL

View file

@ -46,3 +46,39 @@ void asn1_write_octet_string( char *hex_str, char *hex_asn1,
}
}
/* END_CASE */
/* BEGIN_CASE */
void 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 = 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 */