From f8cbf0ae6d15d0c87f74f14de0f6fdf51449054c Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 13 Dec 2018 05:26:04 +0100 Subject: [PATCH] Remove useless whitespace --- .../ConfigFile/WgQuickConfigFileParser.swift | 8 +++--- .../WireGuard/UI/iOS/ErrorPresenter.swift | 4 +-- .../iOS/TunnelEditTableViewController.swift | 26 +++++++++---------- .../UI/iOS/UITableViewCell+Reuse.swift | 2 +- WireGuard/WireGuard/VPN/TunnelsManager.swift | 10 +++---- .../PacketTunnelSettingsGenerator.swift | 18 ++++++------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/WireGuard/WireGuard/ConfigFile/WgQuickConfigFileParser.swift b/WireGuard/WireGuard/ConfigFile/WgQuickConfigFileParser.swift index 14a6dfb..a874720 100644 --- a/WireGuard/WireGuard/ConfigFile/WgQuickConfigFileParser.swift +++ b/WireGuard/WireGuard/ConfigFile/WgQuickConfigFileParser.swift @@ -30,7 +30,7 @@ class WgQuickConfigFileParser { var parserState = ParserState.notInASection var attributes = [String: String]() - + for (lineIndex, line) in lines.enumerated() { var trimmedLine: String if let commentRange = line.range(of: "#") { @@ -94,7 +94,7 @@ class WgQuickConfigFileParser { throw ParseError.noInterface } } - + private static func collate(interfaceAttributes attributes: [String: String], name: String) -> InterfaceConfiguration? { // required wg fields guard let privateKeyString = attributes["privatekey"] else { return nil } @@ -130,7 +130,7 @@ class WgQuickConfigFileParser { } return interface } - + private static func collate(peerAttributes attributes: [String: String]) -> PeerConfiguration? { // required wg fields guard let publicKeyString = attributes["publickey"] else { return nil } @@ -160,5 +160,5 @@ class WgQuickConfigFileParser { } return peer } - + } diff --git a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift index 2889694..ccbd00d 100644 --- a/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift +++ b/WireGuard/WireGuard/UI/iOS/ErrorPresenter.swift @@ -7,7 +7,7 @@ import os.log class ErrorPresenter { static func showErrorAlert(error: WireGuardAppError, from sourceVC: UIViewController?, onPresented: (() -> Void)? = nil, onDismissal: (() -> Void)? = nil) { guard let sourceVC = sourceVC else { return } - + let (title, message) = error.alertText() let okAction = UIAlertAction(title: "OK", style: .default) { _ in onDismissal?() @@ -20,7 +20,7 @@ class ErrorPresenter { static func showErrorAlert(title: String, message: String, from sourceVC: UIViewController?, onPresented: (() -> Void)? = nil, onDismissal: (() -> Void)? = nil) { guard let sourceVC = sourceVC else { return } - + let okAction = UIAlertAction(title: "OK", style: .default) { _ in onDismissal?() } diff --git a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift index 7cd96a2..0386b0a 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift @@ -199,13 +199,13 @@ extension TunnelEditTableViewController { return interfaceFieldKeyValueCell(for: tableView, at: indexPath, with: field) } } - + private func generateKeyPairCell(for tableView: UITableView, at indexPath: IndexPath, with field: TunnelViewModel.InterfaceField) -> UITableViewCell { let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath) cell.buttonText = field.rawValue cell.onTapped = { [weak self] in guard let self = self else { return } - + self.tunnelViewModel.interfaceData[.privateKey] = Curve25519.generatePrivateKey().base64EncodedString() if let privateKeyRow = self.interfaceFieldsBySection[indexPath.section].firstIndex(of: .privateKey), let publicKeyRow = self.interfaceFieldsBySection[indexPath.section].firstIndex(of: .publicKey) { @@ -227,7 +227,7 @@ extension TunnelEditTableViewController { private func interfaceFieldKeyValueCell(for tableView: UITableView, at indexPath: IndexPath, with field: TunnelViewModel.InterfaceField) -> UITableViewCell { let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath) cell.key = field.rawValue - + switch field { case .name, .privateKey: cell.placeholderText = "Required" @@ -260,7 +260,7 @@ extension TunnelEditTableViewController { if field == .privateKey { cell.onValueBeingEdited = { [weak self] value in guard let self = self else { return } - + self.tunnelViewModel.interfaceData[.privateKey] = value if let row = self.interfaceFieldsBySection[indexPath.section].firstIndex(of: .publicKey) { self.tableView.reloadRows(at: [IndexPath(row: row, section: indexPath.section)], with: .none) @@ -275,7 +275,7 @@ extension TunnelEditTableViewController { private func peerCell(for tableView: UITableView, at indexPath: IndexPath, with peerData: TunnelViewModel.PeerData) -> UITableViewCell { let peerFieldsToShow = peerData.shouldAllowExcludePrivateIPsControl ? peerFields : peerFields.filter { $0 != .excludePrivateIPs } let field = peerFieldsToShow[indexPath.row] - + switch field { case .deletePeer: return deletePeerCell(for: tableView, at: indexPath, peerData: peerData, field: field) @@ -285,7 +285,7 @@ extension TunnelEditTableViewController { return peerFieldKeyValueCell(for: tableView, at: indexPath, peerData: peerData, field: field) } } - + private func deletePeerCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell { let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath) cell.buttonText = field.rawValue @@ -304,14 +304,14 @@ extension TunnelEditTableViewController { let rowIndexPath = IndexPath(row: row, section: self.interfaceFieldsBySection.count /* First peer section */) self.tableView.insertRows(at: [rowIndexPath], with: .fade) } - + } }) } } return cell } - + private func excludePrivateIPsCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell { let cell: SwitchCell = tableView.dequeueReusableCell(for: indexPath) cell.message = field.rawValue @@ -326,7 +326,7 @@ extension TunnelEditTableViewController { } return cell } - + private func peerFieldKeyValueCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell { let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath) cell.key = field.rawValue @@ -350,11 +350,11 @@ extension TunnelEditTableViewController { cell.isValueValid = !peerData.fieldsWithError.contains(field) cell.value = peerData[field] - + if field == .allowedIPs { cell.onValueBeingEdited = { [weak self, weak peerData] value in guard let self = self, let peerData = peerData else { return } - + let oldValue = peerData.shouldAllowExcludePrivateIPsControl peerData[.allowedIPs] = value if oldValue != peerData.shouldAllowExcludePrivateIPsControl { @@ -372,7 +372,7 @@ extension TunnelEditTableViewController { peerData?[field] = value } } - + return cell } @@ -476,7 +476,7 @@ extension TunnelEditTableViewController { let option = activateOnDemandOptions[indexPath.row - 1] assert(option != .none) activateOnDemandSetting.activateOnDemandOption = option - + let indexPaths = (1 ..< 4).map { IndexPath(row: $0, section: indexPath.section) } UIView.performWithoutAnimation { tableView.reloadRows(at: indexPaths, with: .none) diff --git a/WireGuard/WireGuard/UI/iOS/UITableViewCell+Reuse.swift b/WireGuard/WireGuard/UI/iOS/UITableViewCell+Reuse.swift index 587f7b1..21d9a07 100644 --- a/WireGuard/WireGuard/UI/iOS/UITableViewCell+Reuse.swift +++ b/WireGuard/WireGuard/UI/iOS/UITableViewCell+Reuse.swift @@ -13,7 +13,7 @@ extension UITableView { func register(_: T.Type) { register(T.self, forCellReuseIdentifier: T.reuseIdentifier) } - + func dequeueReusableCell(for indexPath: IndexPath) -> T { //swiftlint:disable:next force_cast return dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as! T diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index 9d48cdb..95ab071 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -268,16 +268,16 @@ class TunnelsManager { private func startObservingTunnelStatuses() { guard statusObservationToken == nil else { return } - + statusObservationToken = NotificationCenter.default.addObserver(forName: .NEVPNStatusDidChange, object: nil, queue: OperationQueue.main) { [weak self] statusChangeNotification in guard let self = self else { return } guard let session = statusChangeNotification.object as? NETunnelProviderSession else { return } guard let tunnelProvider = session.manager as? NETunnelProviderManager else { return } guard let tunnel = self.tunnels.first(where: { $0.tunnelProvider == tunnelProvider }) else { return } - + os_log("Tunnel '%{public}@' connection status changed to '%{public}@'", log: OSLog.default, type: .debug, tunnel.name, "\(tunnel.tunnelProvider.connection.status)") - + // In case our attempt to start the tunnel, didn't succeed if tunnel == self.tunnelBeingActivated { if session.status == .disconnected { @@ -290,7 +290,7 @@ class TunnelsManager { self.tunnelBeingActivated = nil } } - + // In case we're restarting the tunnel if (tunnel.status == .restarting) && (session.status == .disconnected || session.status == .disconnecting) { // Don't change tunnel.status when disconnecting for a restart @@ -300,7 +300,7 @@ class TunnelsManager { } return } - + tunnel.refreshStatus() } } diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift index d97699d..9b83297 100644 --- a/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift +++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelSettingsGenerator.swift @@ -80,12 +80,12 @@ class PacketTunnelSettingsGenerator { } let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: remoteAddress) - + let dnsServerStrings = tunnelConfiguration.interface.dns.map { $0.stringRepresentation() } let dnsSettings = NEDNSSettings(servers: dnsServerStrings) dnsSettings.matchDomains = [""] // All DNS queries must first go through the VPN's DNS networkSettings.dnsSettings = dnsSettings - + let mtu = tunnelConfiguration.interface.mtu ?? 0 if mtu == 0 { // 0 imples automatic MTU, where we set overhead as 80 bytes, which is the worst case for WireGuard @@ -93,16 +93,16 @@ class PacketTunnelSettingsGenerator { } else { networkSettings.mtu = NSNumber(value: mtu) } - + let (ipv4Routes, ipv6Routes) = routes() let (ipv4IncludedRoutes, ipv6IncludedRoutes) = includedRoutes() let (ipv4ExcludedRoutes, ipv6ExcludedRoutes) = excludedRoutes() - + let ipv4Settings = NEIPv4Settings(addresses: ipv4Routes.map { $0.destinationAddress }, subnetMasks: ipv4Routes.map { $0.destinationSubnetMask }) ipv4Settings.includedRoutes = ipv4IncludedRoutes ipv4Settings.excludedRoutes = ipv4ExcludedRoutes networkSettings.ipv4Settings = ipv4Settings - + let ipv6Settings = NEIPv6Settings(addresses: ipv6Routes.map { $0.destinationAddress }, networkPrefixLengths: ipv6Routes.map { $0.destinationNetworkPrefixLength }) ipv6Settings.includedRoutes = ipv6IncludedRoutes ipv6Settings.excludedRoutes = ipv6ExcludedRoutes @@ -122,7 +122,7 @@ class PacketTunnelSettingsGenerator { octets[3] = UInt8(truncatingIfNeeded: subnetMask) return octets.map { String($0) }.joined(separator: ".") } - + private func routes() -> ([NEIPv4Route], [NEIPv6Route]) { var ipv4Routes = [NEIPv4Route]() var ipv6Routes = [NEIPv6Route]() @@ -140,7 +140,7 @@ class PacketTunnelSettingsGenerator { } return (ipv4Routes, ipv6Routes) } - + private func includedRoutes() -> ([NEIPv4Route], [NEIPv6Route]) { var ipv4IncludedRoutes = [NEIPv4Route]() var ipv6IncludedRoutes = [NEIPv6Route]() @@ -155,7 +155,7 @@ class PacketTunnelSettingsGenerator { } return (ipv4IncludedRoutes, ipv6IncludedRoutes) } - + private func excludedRoutes() -> ([NEIPv4Route], [NEIPv6Route]) { var ipv4ExcludedRoutes = [NEIPv4Route]() var ipv6ExcludedRoutes = [NEIPv6Route]() @@ -172,7 +172,7 @@ class PacketTunnelSettingsGenerator { } return (ipv4ExcludedRoutes, ipv6ExcludedRoutes) } - + } private extension Data {