aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-12-22 00:28:18 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-12-22 00:28:18 +0100
commit4ed646973ee4e1871cda792083bf4fe70afa8c3f (patch)
tree4f7df25ce19ada60ed792c729e562cb2b367a72b /WireGuard/WireGuard/UI
parentFix paren typo (diff)
downloadwireguard-apple-4ed646973ee4e1871cda792083bf4fe70afa8c3f.tar.xz
wireguard-apple-4ed646973ee4e1871cda792083bf4fe70afa8c3f.zip
Move name from interface to tunnel
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuard/WireGuard/UI')
-rw-r--r--WireGuard/WireGuard/UI/TunnelViewModel.swift19
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift4
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift2
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift2
4 files changed, 16 insertions, 11 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift
index 0b5b8c0..0be3cb8 100644
--- a/WireGuard/WireGuard/UI/TunnelViewModel.swift
+++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift
@@ -66,6 +66,7 @@ class TunnelViewModel {
var scratchpad = [InterfaceField: String]()
var fieldsWithError = Set<InterfaceField>()
var validatedConfiguration: InterfaceConfiguration?
+ var validatedName: String?
subscript(field: InterfaceField) -> String {
get {
@@ -83,6 +84,7 @@ class TunnelViewModel {
populateScratchpad()
}
validatedConfiguration = nil
+ validatedName = nil
if stringValue.isEmpty {
scratchpad.removeValue(forKey: field)
} else {
@@ -102,7 +104,8 @@ class TunnelViewModel {
func populateScratchpad() {
// Populate the scratchpad from the configuration object
guard let config = validatedConfiguration else { return }
- scratchpad[.name] = config.name
+ guard let name = validatedName else { return }
+ scratchpad[.name] = name
scratchpad[.privateKey] = config.privateKey.base64EncodedString()
scratchpad[.publicKey] = config.publicKey.base64EncodedString()
if !config.addresses.isEmpty {
@@ -120,10 +123,10 @@ class TunnelViewModel {
}
//swiftlint:disable:next cyclomatic_complexity function_body_length
- func save() -> SaveResult<InterfaceConfiguration> {
- if let validatedConfiguration = validatedConfiguration {
+ func save() -> SaveResult<(String, InterfaceConfiguration)> {
+ if let config = validatedConfiguration, let name = validatedName {
// It's already validated and saved
- return .saved(validatedConfiguration)
+ return .saved((name, config))
}
fieldsWithError.removeAll()
guard let name = scratchpad[.name]?.trimmingCharacters(in: .whitespacesAndNewlines), (!name.isEmpty) else {
@@ -138,7 +141,7 @@ class TunnelViewModel {
fieldsWithError.insert(.privateKey)
return .error(tr("alertInvalidInterfaceMessagePrivateKeyInvalid"))
}
- var config = InterfaceConfiguration(name: name, privateKey: privateKey)
+ var config = InterfaceConfiguration(privateKey: privateKey)
var errorMessages = [String]()
if let addressesString = scratchpad[.addresses] {
var addresses = [IPAddressRange]()
@@ -184,7 +187,8 @@ class TunnelViewModel {
guard errorMessages.isEmpty else { return .error(errorMessages.first!) }
validatedConfiguration = config
- return .saved(config)
+ validatedName = name
+ return .saved((name, config))
}
func filterFieldsWithValueOrControl(interfaceFields: [InterfaceField]) -> [InterfaceField] {
@@ -390,6 +394,7 @@ class TunnelViewModel {
var peersData = [PeerData]()
if let tunnelConfiguration = tunnelConfiguration {
interfaceData.validatedConfiguration = tunnelConfiguration.interface
+ interfaceData.validatedName = tunnelConfiguration.name
for (index, peerConfiguration) in tunnelConfiguration.peers.enumerated() {
let peerData = PeerData(index: index)
peerData.validatedConfiguration = peerConfiguration
@@ -453,7 +458,7 @@ class TunnelViewModel {
return .error(tr("alertInvalidPeerMessagePublicKeyDuplicated"))
}
- let tunnelConfiguration = TunnelConfiguration(interface: interfaceConfiguration, peers: peerConfigurations)
+ let tunnelConfiguration = TunnelConfiguration(name: interfaceConfiguration.0, interface: interfaceConfiguration.1, peers: peerConfigurations)
return .saved(tunnelConfiguration)
}
}
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift
index a4f7130..2f8d41f 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift
@@ -101,7 +101,7 @@ class QRScanViewController: UIViewController {
}
func scanDidComplete(withCode code: String) {
- let scannedTunnelConfiguration = try? TunnelConfiguration(code, name: "Scanned")
+ let scannedTunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: code, called: "Scanned")
guard let tunnelConfiguration = scannedTunnelConfiguration else {
scanDidEncounterError(title: tr("alertScanQRCodeInvalidQRCodeTitle"), message: tr("alertScanQRCodeInvalidQRCodeMessage"))
return
@@ -114,7 +114,7 @@ class QRScanViewController: UIViewController {
})
alert.addAction(UIAlertAction(title: tr("actionSave"), style: .default) { [weak self] _ in
guard let title = alert.textFields?[0].text?.trimmingCharacters(in: .whitespacesAndNewlines), !title.isEmpty else { return }
- tunnelConfiguration.interface.name = title
+ tunnelConfiguration.name = title
if let self = self {
self.delegate?.addScannedQRCode(tunnelConfiguration: tunnelConfiguration, qrScanViewController: self) {
self.dismiss(animated: true, completion: nil)
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
index 79dc7b6..17e5130 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift
@@ -98,7 +98,7 @@ class TunnelEditTableViewController: UITableViewController {
let tunnelSaveResult = tunnelViewModel.save()
switch tunnelSaveResult {
case .error(let errorMessage):
- let alertTitle = (tunnelViewModel.interfaceData.validatedConfiguration == nil) ?
+ let alertTitle = (tunnelViewModel.interfaceData.validatedConfiguration == nil || tunnelViewModel.interfaceData.validatedName == nil) ?
tr("alertInvalidInterfaceTitle") : tr("alertInvalidPeerTitle")
ErrorPresenter.showErrorAlert(title: alertTitle, message: errorMessage, from: self)
tableView.reloadData() // Highlight erroring fields
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
index 77952c8..5e4583e 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
@@ -180,7 +180,7 @@ class TunnelsListTableViewController: UIViewController {
} else /* if (url.pathExtension == "conf") -- we assume everything else is a conf */ {
let fileBaseName = url.deletingPathExtension().lastPathComponent.trimmingCharacters(in: .whitespacesAndNewlines)
if let fileContents = try? String(contentsOf: url),
- let tunnelConfiguration = try? TunnelConfiguration(fileContents, name: fileBaseName) {
+ let tunnelConfiguration = try? TunnelConfiguration(fromWgQuickConfig: fileContents, called: fileBaseName) {
tunnelsManager.add(tunnelConfiguration: tunnelConfiguration) { [weak self] result in
if let error = result.error {
ErrorPresenter.showErrorAlert(error: error, from: self, onPresented: completionHandler)