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