Seems like the outermost if clause is a duplicate of AFSSLPinningModeCertificate logic. Works just fine but would also work w/o the outer if. Is that an optimization?

Here's the same function w/o the outer if:

<pre>
- (void)connection:(NSURLConnection *)connection
willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
    if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
        SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
        switch (self.SSLPinningMode) {
            case AFSSLPinningModePublicKey: {
                id publicKey = (__bridge_transfer id)SecTrustCopyPublicKey(serverTrust);
                
                if ([[self.class pinnedPublicKeys] containsObject:publicKey]) {
                    NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
                    [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
                } else {
                    [[challenge sender] cancelAuthenticationChallenge:challenge];
                }
                
                break;
            }
            case AFSSLPinningModeCertificate: {
                SecCertificateRef serverCertificate = SecTrustGetCertificateAtIndex(serverTrust, 0);
                NSData *serverCertificateData = (__bridge_transfer NSData *)SecCertificateCopyData(serverCertificate);
                
                if ([[[self class] pinnedCertificates] containsObject:serverCertificateData]) {
                    NSURLCredential *credential = [NSURLCredential credentialForTrust:serverTrust];
                    [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
                } else {
                    [[challenge sender] cancelAuthenticationChallenge:challenge];
                }
                
                break;
            }
        }
    }
}
</pre>