Add tests for OID parsing from string
Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
parent
92337c0e62
commit
0f852c9277
2 changed files with 38 additions and 0 deletions
|
@ -119,3 +119,15 @@ oid_get_numeric_string:"8001":MBEDTLS_ERR_ASN1_INVALID_DATA:""
|
|||
|
||||
OID get numeric string - overlong encoding, second subidentifier
|
||||
oid_get_numeric_string:"2B8001":MBEDTLS_ERR_ASN1_INVALID_DATA:""
|
||||
|
||||
OID from numeric string - hardware module name
|
||||
oid_from_numeric_string:"1.3.6.1.5.5.7.8.4":0:"2B06010505070804"
|
||||
|
||||
OID from numeric string - multi-byte subidentifier
|
||||
oid_from_numeric_string:"1.1.2108":0:"29903C"
|
||||
|
||||
OID from numeric string - second component greater than 39
|
||||
oid_from_numeric_string:"2.49.0.0.826.0":0:"81010000863A00"
|
||||
|
||||
OID from numeric string - multi-byte first subidentifier
|
||||
oid_from_numeric_string:"2.999":0:"8837"
|
||||
|
|
|
@ -117,3 +117,29 @@ void oid_get_numeric_string(data_t *oid, int error_ret, char *result_str)
|
|||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void oid_from_numeric_string(char *oid_str, int error_ret,
|
||||
data_t *exp_oid_buf)
|
||||
{
|
||||
mbedtls_asn1_buf oid = { 0, 0, NULL };
|
||||
mbedtls_asn1_buf exp_oid = { 0, 0, NULL };
|
||||
int ret;
|
||||
|
||||
exp_oid.tag = MBEDTLS_ASN1_OID;
|
||||
exp_oid.p = exp_oid_buf->x;
|
||||
exp_oid.len = exp_oid_buf->len;
|
||||
|
||||
ret = mbedtls_oid_from_numeric_string(&oid, oid_str, strlen(oid_str));
|
||||
|
||||
if (error_ret == 0) {
|
||||
TEST_EQUAL(oid.len, exp_oid.len);
|
||||
TEST_ASSERT(memcmp(oid.p, exp_oid.p, oid.len) == 0);
|
||||
mbedtls_free(oid.p);
|
||||
oid.p = NULL;
|
||||
oid.len = 0;
|
||||
} else {
|
||||
TEST_EQUAL(ret, error_ret);
|
||||
}
|
||||
}
|
||||
/* END_CASE */
|
||||
|
|
Loading…
Reference in a new issue