This allows us to easily reuse this function with NWF --- libavformat/tls_apple.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
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) -- 2.21.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".