mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2025-12-24 00:06:32 +01:00
Test and fix x509_oid functions
This commit is contained in:
parent
6c1a73e061
commit
7afdb88216
8 changed files with 91 additions and 10 deletions
|
|
@ -265,6 +265,57 @@ void x509_crt_parse_path( char *crt_path, int ret, int nb_crt )
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void x509_oid_desc( char *oid_str, char *ref_desc )
|
||||
{
|
||||
x509_buf oid;
|
||||
const char *desc;
|
||||
unsigned char buf[20];
|
||||
|
||||
memset( buf, 0, sizeof buf );
|
||||
|
||||
oid.tag = ASN1_OID;
|
||||
oid.len = unhexify( buf, oid_str );
|
||||
oid.p = buf;
|
||||
|
||||
desc = x509_oid_get_description( &oid );
|
||||
|
||||
if( strcmp( ref_desc, "notfound" ) == 0 )
|
||||
TEST_ASSERT( desc == NULL );
|
||||
else
|
||||
{
|
||||
TEST_ASSERT( desc != NULL );
|
||||
TEST_ASSERT( strcmp( desc, ref_desc ) == 0 );
|
||||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void x509_oid_numstr( char *oid_str, char *numstr, int blen, int ret )
|
||||
{
|
||||
x509_buf oid;
|
||||
unsigned char oid_buf[20];
|
||||
char num_buf[100];
|
||||
|
||||
memset( oid_buf, 0x00, sizeof oid_buf );
|
||||
memset( num_buf, 0x2a, sizeof num_buf );
|
||||
|
||||
oid.tag = ASN1_OID;
|
||||
oid.len = unhexify( oid_buf, oid_str );
|
||||
oid.p = oid_buf;
|
||||
|
||||
TEST_ASSERT( (size_t) blen <= sizeof num_buf );
|
||||
|
||||
TEST_ASSERT( x509_oid_get_numeric_string( num_buf, blen, &oid ) == ret );
|
||||
|
||||
if( ret >= 0 )
|
||||
{
|
||||
TEST_ASSERT( num_buf[ret] == 0 );
|
||||
TEST_ASSERT( strcmp( num_buf, numstr ) == 0 );
|
||||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:POLARSSL_X509_CRT_PARSE_C:POLARSSL_SELF_TEST */
|
||||
void x509_selftest()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue