]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/kc/kc-52-testCFEqualAndHash.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / regressions / kc / kc-52-testCFEqualAndHash.c
1 #include <stdlib.h>
2 #include <CoreFoundation/CoreFoundation.h>
3 #include <Security/Security.h>
4
5 #include "testmore.h"
6 #include "testenv.h"
7
8 /* ==========================================================================
9 This test is to ensure we do not regress the fix for radar
10 <rdar://problem/9583502> Security CF runtime objects do not implement CF's Hash function
11 ========================================================================== */
12
13 static void tests(void)
14 {
15 CFDictionaryRef query = CFDictionaryCreate(NULL, (const void **)&kSecClass, (const void **)&kSecClassCertificate, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
16 ok_status(NULL != query, "Dictionary Creation"); // 1
17
18 CFTypeRef result = NULL;
19 OSStatus err = SecItemCopyMatching(query, &result);
20 ok_status(noErr == err && NULL != result, "SecItemCopyMatching"); // 2
21
22 CFRelease(query);
23
24
25 SecCertificateRef cert = (SecCertificateRef)result;
26
27
28 CFDataRef cert_data = SecCertificateCopyData(cert);
29 ok_status(NULL != cert_data, "SecCertificateCopyData"); // 3
30
31 SecCertificateRef certs[5];
32 certs[0] = cert;
33
34 for (int iCnt = 1; iCnt < 5; iCnt++)
35 {
36 cert = NULL;
37 cert = SecCertificateCreateWithData(NULL, cert_data);
38 ok_status(NULL != cert_data, "SecCertificateCreateWithData"); // 4 5 6 7
39 certs[iCnt] = cert;
40 }
41
42 CFSetRef aSet = CFSetCreate(NULL, (const void **)certs, 4, &kCFTypeSetCallBacks);
43 ok_status(NULL != aSet, "CFSetCreate"); // 8
44
45
46 CFIndex count = CFSetGetCount(aSet);
47 ok_status(count == 1, "CFSetGetCount"); // 9
48
49
50 for (int iCnt = 0; iCnt < 5; iCnt++)
51 {
52 cert = certs[iCnt];
53 if (NULL != cert)
54 {
55 CFRelease(cert);
56 certs[iCnt] = NULL;
57 }
58 }
59
60 }
61
62 int main(int argc, char *const *argv)
63 {
64 plan_tests(9);
65 if (!tests_begin(argc, argv))
66 BAIL_OUT("tests_begin failed");
67
68 tests();
69
70 //ok_leaks("leaks");
71
72 return 0;
73 }