@@ -37,11 +37,89 @@ static int test_pathlen(void)
3737 return ret ;
3838}
3939
40+ static int test_asid (void )
41+ {
42+ ASN1_INTEGER * val1 = NULL , * val2 = NULL ;
43+ ASIdentifiers * asid1 = ASIdentifiers_new (), * asid2 = ASIdentifiers_new (),
44+ * asid3 = ASIdentifiers_new (), * asid4 = ASIdentifiers_new ();
45+ int testresult = 0 ;
46+
47+ if (!TEST_ptr (asid1 )
48+ || !TEST_ptr (asid2 )
49+ || !TEST_ptr (asid3 ))
50+ goto err ;
51+
52+ if (!TEST_ptr (val1 = ASN1_INTEGER_new ())
53+ || !TEST_true (ASN1_INTEGER_set_int64 (val1 , 64496 )))
54+ goto err ;
55+
56+ if (!TEST_true (X509v3_asid_add_id_or_range (asid1 , V3_ASID_ASNUM , val1 , NULL )))
57+ goto err ;
58+
59+ val1 = NULL ;
60+ if (!TEST_ptr (val2 = ASN1_INTEGER_new ())
61+ || !TEST_true (ASN1_INTEGER_set_int64 (val2 , 64497 )))
62+ goto err ;
63+
64+ if (!TEST_true (X509v3_asid_add_id_or_range (asid2 , V3_ASID_ASNUM , val2 , NULL )))
65+ goto err ;
66+
67+ val2 = NULL ;
68+ if (!TEST_ptr (val1 = ASN1_INTEGER_new ())
69+ || !TEST_true (ASN1_INTEGER_set_int64 (val1 , 64496 ))
70+ || !TEST_ptr (val2 = ASN1_INTEGER_new ())
71+ || !TEST_true (ASN1_INTEGER_set_int64 (val2 , 64497 )))
72+ goto err ;
73+
74+ /*
75+ * Just tests V3_ASID_ASNUM for now. Could be extended at some point to also
76+ * test V3_ASID_RDI if we think it is worth it.
77+ */
78+ if (!TEST_true (X509v3_asid_add_id_or_range (asid3 , V3_ASID_ASNUM , val1 , val2 )))
79+ goto err ;
80+ val1 = val2 = NULL ;
81+
82+ /* Actual subsets */
83+ if (!TEST_true (X509v3_asid_subset (NULL , NULL ))
84+ || !TEST_true (X509v3_asid_subset (NULL , asid1 ))
85+ || !TEST_true (X509v3_asid_subset (asid1 , asid1 ))
86+ || !TEST_true (X509v3_asid_subset (asid2 , asid2 ))
87+ || !TEST_true (X509v3_asid_subset (asid1 , asid3 ))
88+ || !TEST_true (X509v3_asid_subset (asid2 , asid3 ))
89+ || !TEST_true (X509v3_asid_subset (asid3 , asid3 ))
90+ || !TEST_true (X509v3_asid_subset (asid4 , asid1 ))
91+ || !TEST_true (X509v3_asid_subset (asid4 , asid2 ))
92+ || !TEST_true (X509v3_asid_subset (asid4 , asid3 )))
93+ goto err ;
94+
95+ /* Not subsets */
96+ if (!TEST_false (X509v3_asid_subset (asid1 , NULL ))
97+ || !TEST_false (X509v3_asid_subset (asid1 , asid2 ))
98+ || !TEST_false (X509v3_asid_subset (asid2 , asid1 ))
99+ || !TEST_false (X509v3_asid_subset (asid3 , asid1 ))
100+ || !TEST_false (X509v3_asid_subset (asid3 , asid2 ))
101+ || !TEST_false (X509v3_asid_subset (asid1 , asid4 ))
102+ || !TEST_false (X509v3_asid_subset (asid2 , asid4 ))
103+ || !TEST_false (X509v3_asid_subset (asid3 , asid4 )))
104+ goto err ;
105+
106+ testresult = 1 ;
107+ err :
108+ ASN1_INTEGER_free (val1 );
109+ ASN1_INTEGER_free (val2 );
110+ ASIdentifiers_free (asid1 );
111+ ASIdentifiers_free (asid2 );
112+ ASIdentifiers_free (asid3 );
113+ ASIdentifiers_free (asid4 );
114+ return testresult ;
115+ }
116+
40117int setup_tests (void )
41118{
42119 if (!TEST_ptr (infile = test_get_argument (0 )))
43120 return 0 ;
44121
45122 ADD_TEST (test_pathlen );
123+ ADD_TEST (test_asid );
46124 return 1 ;
47125}
0 commit comments