]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Linter: Fix all linter issues across the codebase
authorAndrej Mihajlov <and@mullvad.net>
Wed, 2 Dec 2020 14:08:45 +0000 (15:08 +0100)
committerAndrej Mihajlov <and@mullvad.net>
Thu, 3 Dec 2020 12:32:25 +0000 (13:32 +0100)
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
12 files changed:
Sources/Shared/Keychain.swift
Sources/WireGuardApp/Tunnel/TunnelsManager.swift
Sources/WireGuardApp/UI/iOS/ViewController/TunnelDetailTableViewController.swift
Sources/WireGuardApp/UI/iOS/ViewController/TunnelsListTableViewController.swift
Sources/WireGuardApp/ZipArchive/ZipArchive.swift
Sources/WireGuardKitSwift/Array+ConcurrentMap.swift
Sources/WireGuardKitSwift/DNSResolver.swift
Sources/WireGuardKitSwift/IPAddress+AddrInfo.swift
Sources/WireGuardKitSwift/PrivateKey.swift
Sources/WireGuardKitSwift/WireGuardAdapter.swift
WireGuard.xcodeproj/project.pbxproj
WireGuard.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

index 3059c579a8d5003af5b9216b38aed04a9cac4ac8..8f40e27a4b548cfa55b02364ae5c93627d71b8de 100644 (file)
@@ -21,18 +21,18 @@ class Keychain {
 
     static func makeReference(containing value: String, called name: String, previouslyReferencedBy oldRef: Data? = nil) -> Data? {
         var ret: OSStatus
-        guard var id = Bundle.main.bundleIdentifier else {
+        guard var bundleIdentifier = Bundle.main.bundleIdentifier else {
             wg_log(.error, staticMessage: "Unable to determine bundle identifier")
             return nil
         }
-        if id.hasSuffix(".network-extension") {
-            id.removeLast(".network-extension".count)
+        if bundleIdentifier.hasSuffix(".network-extension") {
+            bundleIdentifier.removeLast(".network-extension".count)
         }
         var items: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
                                     kSecAttrLabel as String: "WireGuard Tunnel: " + name,
                                     kSecAttrAccount as String: name + ": " + UUID().uuidString,
                                     kSecAttrDescription as String: "wg-quick(8) config",
-                                    kSecAttrService as String: id,
+                                    kSecAttrService as String: bundleIdentifier,
                                     kSecValueData as String: value.data(using: .utf8) as Any,
                                     kSecReturnPersistentRef as String: true]
 
index af6a9bb814588d26e2cfb04bcf78e0cc179db86a..73c7f34b905d96be21c9e8cd43e9229a417c48db 100644 (file)
@@ -464,8 +464,8 @@ class TunnelsManager {
         }
     }
 
-    static func tunnelNameIsLessThan(_ a: String, _ b: String) -> Bool {
-        return a.compare(b, options: [.caseInsensitive, .diacriticInsensitive, .widthInsensitive, .numeric]) == .orderedAscending
+    static func tunnelNameIsLessThan(_ lhs: String, _ rhs: String) -> Bool {
+        return lhs.compare(rhs, options: [.caseInsensitive, .diacriticInsensitive, .widthInsensitive, .numeric]) == .orderedAscending
     }
 }
 
@@ -701,8 +701,8 @@ class CatalinaWorkaround {
     }
 
     func reinstateTunnelsDeletedOutsideApp() {
-        let rd = reinstationDataForTunnelsDeletedOutsideApp()
-        reinstateTunnels(ArraySlice(rd), completionHandler: nil)
+        let data = reinstationDataForTunnelsDeletedOutsideApp()
+        reinstateTunnels(ArraySlice(data), completionHandler: nil)
     }
 
     private func reinstateTunnels(_ rdArray: ArraySlice<ReinstationData>, completionHandler: (() -> Void)?) {
index d49acbc9795825d7657f68b7c6a2fcb5117a9cb2..d3008c2a65ef674c60f386b8d575ef515ff81fa0 100644 (file)
@@ -153,8 +153,8 @@ class TunnelDetailTableViewController: UITableViewController {
             }
         }!
         let firstPeerSectionIndex = interfaceSectionIndex + 1
-        var interfaceFieldIsVisible = self.interfaceFieldIsVisible
-        var peerFieldIsVisible = self.peerFieldIsVisible
+        let interfaceFieldIsVisible = self.interfaceFieldIsVisible
+        let peerFieldIsVisible = self.peerFieldIsVisible
 
         func handleSectionFieldsModified<T>(fields: [T], fieldIsVisible: [Bool], section: Int, changes: [T: TunnelViewModel.Changes.FieldChange]) {
             for (index, field) in fields.enumerated() {
index f442420bafecde3b1e8d05486c7865ea2562d347..885e8c9dfa2614d54f83006e75026d172e591ec3 100644 (file)
@@ -417,12 +417,12 @@ extension TunnelsListTableViewController: TunnelsManagerListDelegate {
 }
 
 extension UISplitViewController {
-    func showDetailViewController(_ vc: UIViewController, sender: Any?, animated: Bool) {
+    func showDetailViewController(_ viewController: UIViewController, sender: Any?, animated: Bool) {
         if animated {
-            showDetailViewController(vc, sender: sender)
+            showDetailViewController(viewController, sender: sender)
         } else {
             UIView.performWithoutAnimation {
-                showDetailViewController(vc, sender: sender)
+                showDetailViewController(viewController, sender: sender)
             }
         }
     }
index 9c2f634727697f3af433804f5351d1cdfd7bf4f2..78419b37b373be44e628e3e234b4b69066b12c9f 100644 (file)
@@ -47,7 +47,7 @@ extension ZipArchive {
     static func unarchive(url: URL, requiredFileExtensions: [String]) throws -> [(fileBaseName: String, contents: Data)] {
 
         var results = [(fileBaseName: String, contents: Data)]()
-        var requiredFileExtensionsLowercased = requiredFileExtensions.map { $0.lowercased() }
+        let requiredFileExtensionsLowercased = requiredFileExtensions.map { $0.lowercased() }
 
         guard let zipFile = unzOpen64(url.path) else {
             throw ZipArchiveError.cantOpenInputZipFile
@@ -62,8 +62,8 @@ extension ZipArchive {
             guard unzOpenCurrentFile(zipFile) == UNZ_OK else { throw ZipArchiveError.badArchive }
 
             let bufferSize = 16384 // 16 KiB
-            var fileNameBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
-            var dataBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
+            let fileNameBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
+            let dataBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: bufferSize)
 
             defer {
                 fileNameBuffer.deallocate()
index 8a7992a7e74dfa18595c49d225bbbb0847016ba9..0059cc3bf206105be4fb7e105f7be88b356a93aa 100644 (file)
@@ -21,7 +21,7 @@ extension Array {
         let execute = queue?.sync ?? { $0() }
 
         execute {
-            DispatchQueue.concurrentPerform(iterations: self.count) { (index) in
+            DispatchQueue.concurrentPerform(iterations: self.count) { index in
                 let value = transform(self[index])
                 resultQueue.sync {
                     result[index] = value
index df19cb24311ddf2ca60159a353009848bbc16613..379c6982429e3efecc9ae965a241dbc58f8b6723 100644 (file)
@@ -12,25 +12,27 @@ extension DNSResolver {
     private static let resolverQueue = DispatchQueue(label: "DNSResolverQueue", qos: .default, attributes: .concurrent)
 
     static func resolveSync(endpoints: [Endpoint?]) -> [Result<Endpoint, DNSResolutionError>?] {
-        let isAllEndpointsAlreadyResolved = endpoints.allSatisfy({ (maybeEndpoint) -> Bool in
+        let isAllEndpointsAlreadyResolved = endpoints.allSatisfy { maybeEndpoint -> Bool in
             return maybeEndpoint?.hasHostAsIPAddress() ?? true
-        })
+        }
 
         if isAllEndpointsAlreadyResolved {
-            return endpoints.map { (endpoint) in
+            return endpoints.map { endpoint in
                 return endpoint.map { .success($0) }
             }
         }
 
-        return endpoints.concurrentMap(queue: resolverQueue) {
-            (endpoint) -> Result<Endpoint, DNSResolutionError>? in
+        return endpoints.concurrentMap(queue: resolverQueue) { endpoint -> Result<Endpoint, DNSResolutionError>? in
             guard let endpoint = endpoint else { return nil }
 
             if endpoint.hasHostAsIPAddress() {
                 return .success(endpoint)
             } else {
                 return Result { try DNSResolver.resolveSync(endpoint: endpoint) }
-                    .mapError { $0 as! DNSResolutionError }
+                    .mapError { error -> DNSResolutionError in
+                        // swiftlint:disable:next force_cast
+                        return error as! DNSResolutionError
+                    }
             }
         }
     }
index d8600770d737504956596b2fe46c1406f24fdc99..b7e8cd503de1f3252f5e22eb3e15cfcb9eec84aa 100644 (file)
@@ -8,7 +8,7 @@ extension IPv4Address {
     init?(addrInfo: addrinfo) {
         guard addrInfo.ai_family == AF_INET else { return nil }
 
-        let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in.self, capacity: MemoryLayout<sockaddr_in>.size) { (ptr) -> Data in
+        let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in.self, capacity: MemoryLayout<sockaddr_in>.size) { ptr -> Data in
             return Data(bytes: &ptr.pointee.sin_addr, count: MemoryLayout<in_addr>.size)
         }
 
@@ -24,7 +24,7 @@ extension IPv6Address {
     init?(addrInfo: addrinfo) {
         guard addrInfo.ai_family == AF_INET6 else { return nil }
 
-        let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in6.self, capacity: MemoryLayout<sockaddr_in6>.size) { (ptr) -> Data in
+        let addressData = addrInfo.ai_addr.withMemoryRebound(to: sockaddr_in6.self, capacity: MemoryLayout<sockaddr_in6>.size) { ptr -> Data in
             return Data(bytes: &ptr.pointee.sin6_addr, count: MemoryLayout<in6_addr>.size)
         }
 
index 14c298f49ef7d92f2f8d391cee8663ef7e0642ed..545cdbc67508cdff000bb3c2dfab438c51b9426a 100644 (file)
@@ -5,7 +5,7 @@ import Foundation
 import WireGuardKitC
 
 /// The class describing a private key used by WireGuard.
-public class PrivateKey: _BaseKey {
+public class PrivateKey: BaseKey {
     /// Derived public key
     public var publicKey: PublicKey {
         return rawValue.withUnsafeBytes { (privateKeyBufferPointer: UnsafeRawBufferPointer) -> PublicKey in
@@ -33,13 +33,13 @@ public class PrivateKey: _BaseKey {
 }
 
 /// The class describing a public key used by WireGuard.
-public class PublicKey: _BaseKey {}
+public class PublicKey: BaseKey {}
 
 /// The class describing a pre-shared key used by WireGuard.
-public class PreSharedKey: _BaseKey {}
+public class PreSharedKey: BaseKey {}
 
 /// The base key implementation. Should not be used directly.
-public class _BaseKey: RawRepresentable, Equatable, Hashable {
+public class BaseKey: RawRepresentable, Equatable, Hashable {
     /// Raw key representation
     public let rawValue: Data
 
@@ -98,7 +98,7 @@ public class _BaseKey: RawRepresentable, Equatable, Hashable {
         }
     }
 
-    public static func == (lhs: _BaseKey, rhs: _BaseKey) -> Bool {
+    public static func == (lhs: BaseKey, rhs: BaseKey) -> Bool {
         return lhs.rawValue.withUnsafeBytes { (lhsBytes: UnsafeRawBufferPointer) -> Bool in
             return rhs.rawValue.withUnsafeBytes { (rhsBytes: UnsafeRawBufferPointer) -> Bool in
                 return key_eq(
index 2e8df6f799bf633deedcc235773a637917ec8676..ef644bdb23ff01bbb38643f819d6f7cb24717989 100644 (file)
@@ -64,7 +64,7 @@ public class WireGuardAdapter {
 
         var buffer = [UInt8](repeating: 0, count: Int(IFNAMSIZ))
 
-        return buffer.withUnsafeMutableBufferPointer { (mutableBufferPointer) in
+        return buffer.withUnsafeMutableBufferPointer { mutableBufferPointer in
             guard let baseAddress = mutableBufferPointer.baseAddress else { return nil }
 
             var ifnameSize = socklen_t(IFNAMSIZ)
@@ -158,7 +158,7 @@ public class WireGuardAdapter {
             networkMonitor.start(queue: self.workQueue)
             self.networkMonitor = networkMonitor
 
-            self.updateNetworkSettings(tunnelConfiguration: tunnelConfiguration) { (settingsGenerator, error) in
+            self.updateNetworkSettings(tunnelConfiguration: tunnelConfiguration) { settingsGenerator, error in
                 if let error = error {
                     completionHandler(error)
                 } else {
@@ -212,7 +212,7 @@ public class WireGuardAdapter {
             // This will broadcast the `NEVPNStatusDidChange` notification to the GUI process.
             self.packetTunnelProvider?.reasserting = true
 
-            self.updateNetworkSettings(tunnelConfiguration: tunnelConfiguration) { (settingsGenerator, error) in
+            self.updateNetworkSettings(tunnelConfiguration: tunnelConfiguration) { settingsGenerator, error in
                 if let error = error {
                     completionHandler(error)
                 } else {
@@ -230,7 +230,7 @@ public class WireGuardAdapter {
     /// Setup WireGuard log handler.
     private func setupLogHandler() {
         let context = Unmanaged.passUnretained(self).toOpaque()
-        wgSetLogger(context) { (context, logLevel, message) in
+        wgSetLogger(context) { context, logLevel, message in
             guard let context = context, let message = message else { return }
 
             let unretainedSelf = Unmanaged<WireGuardAdapter>.fromOpaque(context)
@@ -251,7 +251,10 @@ public class WireGuardAdapter {
         let resolvedEndpoints: [Endpoint?]
 
         let resolvePeersResult = Result { try self.resolvePeers(for: tunnelConfiguration) }
-            .mapError { $0 as! WireGuardAdapterError }
+            .mapError { error -> WireGuardAdapterError in
+                // swiftlint:disable:next force_cast
+                return error as! WireGuardAdapterError
+            }
 
         switch resolvePeersResult {
         case .success(let endpoints):
@@ -271,10 +274,10 @@ public class WireGuardAdapter {
         condition.lock()
         defer { condition.unlock() }
 
-        self.packetTunnelProvider?.setTunnelNetworkSettings(networkSettings, completionHandler: { (error) in
+        self.packetTunnelProvider?.setTunnelNetworkSettings(networkSettings) { error in
             systemError = error
             condition.signal()
-        })
+        }
 
         // Packet tunnel's `setTunnelNetworkSettings` times out in certain
         // scenarios & never calls the given callback.
@@ -301,7 +304,7 @@ public class WireGuardAdapter {
     private func resolvePeers(for tunnelConfiguration: TunnelConfiguration) throws -> [Endpoint?] {
         let endpoints = tunnelConfiguration.peers.map { $0.endpoint }
         let resolutionResults = DNSResolver.resolveSync(endpoints: endpoints)
-        let resolutionErrors = resolutionResults.compactMap { (result) -> DNSResolutionError? in
+        let resolutionErrors = resolutionResults.compactMap { result -> DNSResolutionError? in
             if case .failure(let error) = result {
                 return error
             } else {
@@ -313,7 +316,8 @@ public class WireGuardAdapter {
             throw WireGuardAdapterError.dnsResolution(resolutionErrors)
         }
 
-        let resolvedEndpoints = resolutionResults.map { (result) -> Endpoint? in
+        let resolvedEndpoints = resolutionResults.map { result -> Endpoint? in
+            // swiftlint:disable:next force_try
             return try! result?.get()
         }
 
index c6e9f700d0714de240408452a6892bcd8d28d187..c9b51a5f7cf2d4d03411d2c8ade4d379274f78ed 100644 (file)
                        isa = XCRemoteSwiftPackageReference;
                        repositoryURL = "https://git.zx2c4.com/wireguard-apple";
                        requirement = {
-                               branch = master;
+                               branch = "am/wg-adapter-rebased";
                                kind = branch;
                        };
                };
index 01be9af1696e647a9180abb0f635f3c9caf0bc92..4aeec04f2ef2c79f5c6d79e38077f124d42423bd 100644 (file)
@@ -5,8 +5,8 @@
         "package": "WireGuardKit",
         "repositoryURL": "https://git.zx2c4.com/wireguard-apple",
         "state": {
-          "branch": "master",
-          "revision": "737f847c0db36429f7136fb514409c22e13a70ee",
+          "branch": "am/wg-adapter-rebased",
+          "revision": "e52f83b915a985a945dff622e5f48fa52e96f045",
           "version": null
         }
       }