From 11876574979e42b18824f65cc64522431bcd4f1d Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 25 Oct 2018 06:58:14 +0530 Subject: [PATCH] Model: Allow creating an interface with empty name But don't allow such a tunnel to be added to the tunnel manager. (We'll need to create an interface with an empty name when we're reading QR codes.) Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/Model/Configuration.swift | 1 - WireGuard/WireGuard/UI/TunnelViewModel.swift | 2 +- WireGuard/WireGuard/VPN/TunnelsManager.swift | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WireGuard/WireGuard/Model/Configuration.swift b/WireGuard/WireGuard/Model/Configuration.swift index 8ef93e6..4bed41b 100644 --- a/WireGuard/WireGuard/Model/Configuration.swift +++ b/WireGuard/WireGuard/Model/Configuration.swift @@ -28,7 +28,6 @@ struct InterfaceConfiguration: Codable { init(name: String, privateKey: Data) { self.name = name self.privateKey = privateKey - if (name.isEmpty) { fatalError("Empty name") } if (privateKey.count != 32) { fatalError("Invalid private key") } } } diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift index bc826d5..e5c814f 100644 --- a/WireGuard/WireGuard/UI/TunnelViewModel.swift +++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift @@ -98,7 +98,7 @@ class TunnelViewModel { func save() -> SaveResult { fieldsWithError.removeAll() - guard let name = scratchpad[.name] else { + guard let name = scratchpad[.name], (!name.isEmpty) else { fieldsWithError.insert(.name) return .error("Interface name is required") } diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index 9552c42..48b2767 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -53,6 +53,7 @@ class TunnelsManager { } func add(tunnelConfiguration: TunnelConfiguration, completionHandler: @escaping (TunnelContainer, Error?) -> Void) { + assert(!tunnelConfiguration.interface.name.isEmpty) let tunnelProvider = TunnelProviderManager(tunnelConfiguration: tunnelConfiguration) for tunnel in tunnels { tunnel.index = tunnel.index + 1