1/* BEGIN_HEADER */ 2#include "mbedtls/oid.h" 3#include "mbedtls/asn1.h" 4#include "mbedtls/asn1write.h" 5#include "string.h" 6#include "mbedtls/legacy_or_psa.h" 7/* END_HEADER */ 8 9/* BEGIN_DEPENDENCIES 10 * depends_on:MBEDTLS_OID_C:!MBEDTLS_X509_REMOVE_INFO 11 * END_DEPENDENCIES 12 */ 13 14/* BEGIN_CASE */ 15void oid_get_certificate_policies(data_t *oid, char *result_str) 16{ 17 mbedtls_asn1_buf asn1_buf = { 0, 0, NULL }; 18 int ret; 19 const char *desc; 20 21 asn1_buf.tag = MBEDTLS_ASN1_OID; 22 asn1_buf.p = oid->x; 23 asn1_buf.len = oid->len; 24 25 ret = mbedtls_oid_get_certificate_policies(&asn1_buf, &desc); 26 if (strlen(result_str) == 0) { 27 TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND); 28 } else { 29 TEST_ASSERT(ret == 0); 30 TEST_ASSERT(strcmp((char *) desc, result_str) == 0); 31 } 32} 33/* END_CASE */ 34 35/* BEGIN_CASE */ 36void oid_get_extended_key_usage(data_t *oid, char *result_str) 37{ 38 mbedtls_asn1_buf asn1_buf = { 0, 0, NULL }; 39 int ret; 40 const char *desc; 41 42 asn1_buf.tag = MBEDTLS_ASN1_OID; 43 asn1_buf.p = oid->x; 44 asn1_buf.len = oid->len; 45 46 ret = mbedtls_oid_get_extended_key_usage(&asn1_buf, &desc); 47 if (strlen(result_str) == 0) { 48 TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND); 49 } else { 50 TEST_ASSERT(ret == 0); 51 TEST_ASSERT(strcmp((char *) desc, result_str) == 0); 52 } 53} 54/* END_CASE */ 55 56/* BEGIN_CASE */ 57void oid_get_x509_extension(data_t *oid, int exp_type) 58{ 59 mbedtls_asn1_buf ext_oid = { 0, 0, NULL }; 60 int ret; 61 int ext_type; 62 63 ext_oid.tag = MBEDTLS_ASN1_OID; 64 ext_oid.p = oid->x; 65 ext_oid.len = oid->len; 66 67 ret = mbedtls_oid_get_x509_ext_type(&ext_oid, &ext_type); 68 if (exp_type == 0) { 69 TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND); 70 } else { 71 TEST_ASSERT(ret == 0); 72 TEST_ASSERT(ext_type == exp_type); 73 } 74} 75/* END_CASE */ 76 77/* BEGIN_CASE */ 78void oid_get_md_alg_id(data_t *oid, int exp_md_id) 79{ 80 mbedtls_asn1_buf md_oid = { 0, 0, NULL }; 81 int ret; 82 mbedtls_md_type_t md_id = 0; 83 84 md_oid.tag = MBEDTLS_ASN1_OID; 85 md_oid.p = oid->x; 86 md_oid.len = oid->len; 87 88 ret = mbedtls_oid_get_md_alg(&md_oid, &md_id); 89 90 if (exp_md_id < 0) { 91 TEST_ASSERT(ret == MBEDTLS_ERR_OID_NOT_FOUND); 92 TEST_ASSERT(md_id == 0); 93 } else { 94 TEST_ASSERT(ret == 0); 95 TEST_ASSERT((mbedtls_md_type_t) exp_md_id == md_id); 96 } 97} 98/* END_CASE */ 99 100/* BEGIN_CASE */ 101void oid_get_numeric_string(data_t *oid, int error_ret, char *result_str) 102{ 103 char buf[256]; 104 mbedtls_asn1_buf input_oid = { 0, 0, NULL }; 105 int ret; 106 107 input_oid.tag = MBEDTLS_ASN1_OID; 108 /* Test that an empty OID is not dereferenced */ 109 input_oid.p = oid->len ? oid->x : (void *) 1; 110 input_oid.len = oid->len; 111 112 ret = mbedtls_oid_get_numeric_string(buf, sizeof(buf), &input_oid); 113 114 if (error_ret == 0) { 115 TEST_EQUAL(ret, strlen(result_str)); 116 TEST_ASSERT(ret >= 3); 117 TEST_EQUAL(strcmp(buf, result_str), 0); 118 } else { 119 TEST_EQUAL(ret, error_ret); 120 } 121} 122/* END_CASE */ 123