Add tests for mbedtls_oid_get_numeric_string()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
parent
c7f700c795
commit
f01de145bd
2 changed files with 45 additions and 0 deletions
|
@ -89,3 +89,27 @@ oid_get_md_alg_id:"2b24030201":MBEDTLS_MD_RIPEMD160
|
|||
OID hash id - invalid oid
|
||||
oid_get_md_alg_id:"2B864886f70d0204":-1
|
||||
|
||||
OID get numeric string - hardware module name
|
||||
oid_get_numeric_string:"2B06010505070804":0:"1.3.6.1.5.5.7.8.4"
|
||||
|
||||
OID get numeric string - multi-byte subidentifier
|
||||
oid_get_numeric_string:"29903C":0:"1.1.2108"
|
||||
|
||||
OID get numeric string - second component greater than 39
|
||||
oid_get_numeric_string:"81010000863A00":0:"2.49.0.0.826.0"
|
||||
|
||||
OID get numeric string - multi-byte first subidentifier
|
||||
oid_get_numeric_string:"8837":0:"2.999"
|
||||
|
||||
OID get numeric string - empty oid buffer
|
||||
oid_get_numeric_string:"":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
||||
|
||||
OID get numeric string - no final / all bytes have top bit set
|
||||
oid_get_numeric_string:"818181":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
||||
|
||||
# Encodes the number 0x0400000000 as a subidentifier which overflows 32-bits
|
||||
OID get numeric string - 32-bit overflow
|
||||
oid_get_numeric_string:"C080808000":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
||||
|
||||
OID get numeric string - 32-bit overflow, second subidentifier
|
||||
oid_get_numeric_string:"2BC080808000":MBEDTLS_ERR_OID_BUF_TOO_SMALL:""
|
||||
|
|
|
@ -96,3 +96,24 @@ void oid_get_md_alg_id(data_t *oid, int exp_md_id)
|
|||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void oid_get_numeric_string(data_t *oid, int error_ret, char *result_str)
|
||||
{
|
||||
char buf[256];
|
||||
mbedtls_asn1_buf input_oid = { 0, 0, NULL };
|
||||
int ret;
|
||||
|
||||
input_oid.tag = MBEDTLS_ASN1_OID;
|
||||
input_oid.p = oid->x;
|
||||
input_oid.len = oid->len;
|
||||
|
||||
ret = mbedtls_oid_get_numeric_string(buf, sizeof(buf), &input_oid);
|
||||
|
||||
if (error_ret == 0) {
|
||||
TEST_ASSERT(strcmp(buf, result_str) == 0);
|
||||
} else {
|
||||
TEST_EQUAL(ret, error_ret);
|
||||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
|
Loading…
Reference in a new issue