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 <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-10-25 06:58:14 +05:30
parent 1c8928c8a1
commit 1187657497
3 changed files with 2 additions and 2 deletions

View File

@ -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") }
}
}

View File

@ -98,7 +98,7 @@ class TunnelViewModel {
func save() -> SaveResult<InterfaceConfiguration> {
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")
}

View File

@ -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