[FFmpeg-devel,2/6] lavf/tls_apple: factor loading SecItemIdentity into its own (Mac-only) function

Submitted by Rodger Combs on June 11, 2019, 2:16 p.m.

Details

Message ID 20190611141623.59440-2-rodger.combs@gmail.com
State New
Headers show

Commit Message

Rodger Combs June 11, 2019, 2:16 p.m.
This allows us to easily reuse this function with NWF
---
 libavformat/tls_apple.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/tls_apple.c b/libavformat/tls_apple.c
index 37380541b1..2ff6622565 100644
--- a/libavformat/tls_apple.c
+++ b/libavformat/tls_apple.c
@@ -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)