From bf3510765a5c82516aabef3a2efd6b136141b9b8 Mon Sep 17 00:00:00 2001 From: Jeroen Leenarts Date: Thu, 16 Aug 2018 22:39:08 +0200 Subject: [PATCH] Use `commaSeparatedToArray` utility everywhere. Signed-off-by: Jason A. Donenfeld --- WireGuard.xcodeproj/project.pbxproj | 2 ++ WireGuard/Models/Tunnel+Extension.swift | 2 +- WireGuardNetworkExtension/PacketTunnelProvider.swift | 8 +++----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WireGuard.xcodeproj/project.pbxproj b/WireGuard.xcodeproj/project.pbxproj index 5035e77..620f25c 100644 --- a/WireGuard.xcodeproj/project.pbxproj +++ b/WireGuard.xcodeproj/project.pbxproj @@ -32,6 +32,7 @@ 4A61D82E20D98CE2006C7A76 /* WireGuardNetworkExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 4A61D82620D98CE1006C7A76 /* WireGuardNetworkExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 4A61D83520D98D25006C7A76 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A61D83420D98D25006C7A76 /* NetworkExtension.framework */; }; 4A8AABD820B6A79100B6D8C1 /* UITableView+WireGuard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8AABD720B6A79100B6D8C1 /* UITableView+WireGuard.swift */; }; + 4AADEA2B212616F7008C24FD /* String+Arrays.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FA1D50F2124D80C00DBA2E6 /* String+Arrays.swift */; }; 4AC086832120B9F900CEE5ED /* ProviderConfigurationKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AC086822120B9F900CEE5ED /* ProviderConfigurationKeys.swift */; }; 4AC086852120BCB500CEE5ED /* ProviderConfigurationKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AC086822120B9F900CEE5ED /* ProviderConfigurationKeys.swift */; }; 4AC086862120BD5800CEE5ED /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A61D82820D98CE2006C7A76 /* PacketTunnelProvider.swift */; }; @@ -586,6 +587,7 @@ 4AC086852120BCB500CEE5ED /* ProviderConfigurationKeys.swift in Sources */, 4AC086862120BD5800CEE5ED /* PacketTunnelProvider.swift in Sources */, 4A43515A2124956200261999 /* Validators.swift in Sources */, + 4AADEA2B212616F7008C24FD /* String+Arrays.swift in Sources */, 4AEAC32920F14B3B007B67AB /* Log.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/WireGuard/Models/Tunnel+Extension.swift b/WireGuard/Models/Tunnel+Extension.swift index f181e77..038e47d 100644 --- a/WireGuard/Models/Tunnel+Extension.swift +++ b/WireGuard/Models/Tunnel+Extension.swift @@ -70,7 +70,7 @@ extension Tunnel { if peer.persistentKeepalive > 0 { settingsString += "persistent_keepalive_interval=\(peer.persistentKeepalive)\n" } - if let allowedIPs = peer.allowedIPs?.split(separator: ",") { + if let allowedIPs = peer.allowedIPs?.commaSeparatedToArray() { allowedIPs.forEach { settingsString += "allowed_ip=\($0.trimmingCharacters(in: .whitespaces))\n" } diff --git a/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuardNetworkExtension/PacketTunnelProvider.swift index 4963ff4..52752fd 100644 --- a/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -32,9 +32,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider { let mtu = config.providerConfiguration![PCKeys.mtu.rawValue] as? NSNumber let settings = config.providerConfiguration![PCKeys.settings.rawValue]! as! String // swiftlint:disable:this force_cast let endpoints = config.providerConfiguration?[PCKeys.endpoints.rawValue] as? String ?? "" - let addresses = (config.providerConfiguration?[PCKeys.addresses.rawValue] as? String ?? "").split(separator: ",") + let addresses = (config.providerConfiguration?[PCKeys.addresses.rawValue] as? String ?? "").commaSeparatedToArray() - let validatedEndpoints = endpoints.split(separator: ",").compactMap { try? Endpoint(endpointString: String($0)) }.compactMap {$0} + let validatedEndpoints = endpoints.commaSeparatedToArray().compactMap { try? Endpoint(endpointString: String($0)) }.compactMap {$0} let validatedAddresses = addresses.compactMap { try? CIDRAddress(stringRepresentation: String($0)) }.compactMap { $0 } if wireGuardWrapper.turnOn(withInterfaceName: interfaceName, settingsString: settings) { @@ -64,9 +64,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider { } if let dns = config.providerConfiguration?[PCKeys.dns.rawValue] as? String { - let splitDnsEntries = dns.split(separator: ",").map {String($0)} - let dnsSettings = NEDNSSettings(servers: splitDnsEntries) - newSettings.dnsSettings = dnsSettings + newSettings.dnsSettings = NEDNSSettings(servers: dns.commaSeparatedToArray()) } if let mtu = mtu, mtu.intValue > 0 { newSettings.mtu = mtu