+static CFArrayRef CF_RETURNS_RETAINED copyCertsFromRawCerts(SecAsn1Item **rawCerts) {
+ CFMutableArrayRef certs = NULL;
+ SecCertificateRef certificate = NULL;
+ int numRawCerts = SecCmsArrayCount((void **)rawCerts);
+ int dex;
+
+ certs = CFArrayCreateMutable(NULL, numRawCerts, &kCFTypeArrayCallBacks);
+
+ for(dex=0; dex<numRawCerts; dex++) {
+ certificate = SecCertificateCreateWithBytes(NULL, rawCerts[dex]->Data, rawCerts[dex]->Length);
+ CFArrayAppendValue(certs, certificate);
+ CFRelease(certificate);
+ certificate = NULL;
+ }
+
+ if (CFArrayGetCount(certs) == 0) {
+ CFRelease(certs);
+ return NULL;
+ }
+ return certs;
+}
+