Use `commaSeparatedToArray` utility everywhere.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jeroen Leenarts 2018-08-16 22:39:08 +02:00
parent 603953a8b8
commit bf3510765a
3 changed files with 6 additions and 6 deletions

View File

@ -32,6 +32,7 @@
4A61D82E20D98CE2006C7A76 /* WireGuardNetworkExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 4A61D82620D98CE1006C7A76 /* WireGuardNetworkExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 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 */; }; 4A61D83520D98D25006C7A76 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A61D83420D98D25006C7A76 /* NetworkExtension.framework */; };
4A8AABD820B6A79100B6D8C1 /* UITableView+WireGuard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A8AABD720B6A79100B6D8C1 /* UITableView+WireGuard.swift */; }; 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 */; }; 4AC086832120B9F900CEE5ED /* ProviderConfigurationKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AC086822120B9F900CEE5ED /* ProviderConfigurationKeys.swift */; };
4AC086852120BCB500CEE5ED /* 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 */; }; 4AC086862120BD5800CEE5ED /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4A61D82820D98CE2006C7A76 /* PacketTunnelProvider.swift */; };
@ -586,6 +587,7 @@
4AC086852120BCB500CEE5ED /* ProviderConfigurationKeys.swift in Sources */, 4AC086852120BCB500CEE5ED /* ProviderConfigurationKeys.swift in Sources */,
4AC086862120BD5800CEE5ED /* PacketTunnelProvider.swift in Sources */, 4AC086862120BD5800CEE5ED /* PacketTunnelProvider.swift in Sources */,
4A43515A2124956200261999 /* Validators.swift in Sources */, 4A43515A2124956200261999 /* Validators.swift in Sources */,
4AADEA2B212616F7008C24FD /* String+Arrays.swift in Sources */,
4AEAC32920F14B3B007B67AB /* Log.swift in Sources */, 4AEAC32920F14B3B007B67AB /* Log.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

View File

@ -70,7 +70,7 @@ extension Tunnel {
if peer.persistentKeepalive > 0 { if peer.persistentKeepalive > 0 {
settingsString += "persistent_keepalive_interval=\(peer.persistentKeepalive)\n" settingsString += "persistent_keepalive_interval=\(peer.persistentKeepalive)\n"
} }
if let allowedIPs = peer.allowedIPs?.split(separator: ",") { if let allowedIPs = peer.allowedIPs?.commaSeparatedToArray() {
allowedIPs.forEach { allowedIPs.forEach {
settingsString += "allowed_ip=\($0.trimmingCharacters(in: .whitespaces))\n" settingsString += "allowed_ip=\($0.trimmingCharacters(in: .whitespaces))\n"
} }

View File

@ -32,9 +32,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
let mtu = config.providerConfiguration![PCKeys.mtu.rawValue] as? NSNumber let mtu = config.providerConfiguration![PCKeys.mtu.rawValue] as? NSNumber
let settings = config.providerConfiguration![PCKeys.settings.rawValue]! as! String // swiftlint:disable:this force_cast let settings = config.providerConfiguration![PCKeys.settings.rawValue]! as! String // swiftlint:disable:this force_cast
let endpoints = config.providerConfiguration?[PCKeys.endpoints.rawValue] as? String ?? "" 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 } let validatedAddresses = addresses.compactMap { try? CIDRAddress(stringRepresentation: String($0)) }.compactMap { $0 }
if wireGuardWrapper.turnOn(withInterfaceName: interfaceName, settingsString: settings) { if wireGuardWrapper.turnOn(withInterfaceName: interfaceName, settingsString: settings) {
@ -64,9 +64,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
} }
if let dns = config.providerConfiguration?[PCKeys.dns.rawValue] as? String { if let dns = config.providerConfiguration?[PCKeys.dns.rawValue] as? String {
let splitDnsEntries = dns.split(separator: ",").map {String($0)} newSettings.dnsSettings = NEDNSSettings(servers: dns.commaSeparatedToArray())
let dnsSettings = NEDNSSettings(servers: splitDnsEntries)
newSettings.dnsSettings = dnsSettings
} }
if let mtu = mtu, mtu.intValue > 0 { if let mtu = mtu, mtu.intValue > 0 {
newSettings.mtu = mtu newSettings.mtu = mtu