Skip to content

Commit

Permalink
Fix optional error
Browse files Browse the repository at this point in the history
  • Loading branch information
ShihabMehboob committed Feb 21, 2018
1 parent 8308eba commit 9fc6da3
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Sources/SwiftyRequest/RestRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -809,28 +809,28 @@ extension RestRequest: URLSessionDelegate {
switch (method, host) {
case (NSURLAuthenticationMethodServerTrust, baseHost):
#if !os(Linux)
guard #available(iOS 3.0, macOS 10.6, *), let trust = challenge.protectionSpace.serverTrust else {
Log.warning(warning)
fallthrough
}
if let certificateData = NSData(contentsOfFile: Bundle.main.path(forResource: self.pinnedCertificateName, ofType: "der")!) {
if let serverCertificate = SecTrustGetCertificateAtIndex(trust, 0) {
let serverCertificateData = SecCertificateCopyData(serverCertificate) as NSData
if certificateData == serverCertificateData {
Log.verbose("Certificate validation successful")
completionHandler(.useCredential, URLCredential(trust: trust))
return
} else {
completionHandler(.performDefaultHandling, nil)
guard #available(iOS 3.0, macOS 10.6, *), let trust = challenge.protectionSpace.serverTrust else {
Log.warning(warning)
fallthrough
}
if let certificateData = NSData(contentsOfFile: Bundle.main.path(forResource: self.pinnedCertificateName, ofType: "der") ?? "") {
if let serverCertificate = SecTrustGetCertificateAtIndex(trust, 0) {
let serverCertificateData = SecCertificateCopyData(serverCertificate) as NSData
if certificateData == serverCertificateData {
Log.verbose("Certificate validation successful")
completionHandler(.useCredential, URLCredential(trust: trust))
return
} else {
completionHandler(.performDefaultHandling, nil)
}
}
}
}

completionHandler(.useCredential, URLCredential(trust: trust))
completionHandler(.useCredential, URLCredential(trust: trust))

#else
Log.warning(warning)
fallthrough
Log.warning(warning)
fallthrough
#endif
default:
completionHandler(.performDefaultHandling, nil)
Expand Down

0 comments on commit 9fc6da3

Please sign in to comment.