@@ -150,28 +150,46 @@ end:
return ret;
}
-static int load_cert(URLContext *h)
+static int load_identity(URLContext *h, SecIdentityRef *identity, CFArrayRef *certArray)
{
+#if !HAVE_SECITEMIMPORT
+ return AVERROR_PATCHWELCOME;
+#else
TLSContext *c = h->priv_data;
int ret = 0;
- CFArrayRef certArray = NULL;
CFArrayRef keyArray = NULL;
- SecIdentityRef id = NULL;
- CFMutableArrayRef outArray = NULL;
- if ((ret = import_pem(h, c->tls_shared.cert_file, &certArray)) < 0)
+ if ((ret = import_pem(h, c->tls_shared.cert_file, certArray)) < 0)
goto end;
if ((ret = import_pem(h, c->tls_shared.key_file, &keyArray)) < 0)
goto end;
- if (!(id = SecIdentityCreate(kCFAllocatorDefault,
- (SecCertificateRef)CFArrayGetValueAtIndex(certArray, 0),
+ if (!(*identity = SecIdentityCreate(kCFAllocatorDefault,
+ (SecCertificateRef)CFArrayGetValueAtIndex(*certArray, 0),
(SecKeyRef)CFArrayGetValueAtIndex(keyArray, 0)))) {
ret = AVERROR_UNKNOWN;
goto end;
}
+end:
+ if (keyArray)
+ CFRelease(keyArray);
+ return ret;
+#endif
+}
+
+static int load_cert(URLContext *h)
+{
+ TLSContext *c = h->priv_data;
+ int ret = 0;
+ SecIdentityRef id = NULL;
+ CFArrayRef certArray = NULL;
+ CFMutableArrayRef outArray = NULL;
+
+ if ((ret = load_identity(h, &id, &certArray)) < 0)
+ goto end;
+
if (!(outArray = CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, certArray))) {
ret = AVERROR(ENOMEM);
goto end;
@@ -184,8 +202,6 @@ static int load_cert(URLContext *h)
end:
if (certArray)
CFRelease(certArray);
- if (keyArray)
- CFRelease(keyArray);
if (outArray)
CFRelease(outArray);
if (id)