aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-08 15:44:17 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:34 +0530
commitc2a6241b5c1016c089f82e412c29236fdb1bbea6 (patch)
treed45289d0c7049da8ba1e23240c1d629ec2cc50e7 /WireGuard/WireGuard/UI
parentSyntax highlighter color updates (diff)
downloadwireguard-apple-c2a6241b5c1016c089f82e412c29236fdb1bbea6.tar.xz
wireguard-apple-c2a6241b5c1016c089f82e412c29236fdb1bbea6.zip
macOS: Refactor config file parsing
- To report more fine grained errors - To make the parse errors conform to WireGuardAppError Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift50
1 files changed, 50 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift b/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift
new file mode 100644
index 0000000..4a1c890
--- /dev/null
+++ b/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018 WireGuard LLC. All Rights Reserved.
+
+import Cocoa
+
+// We have this in a separate file because we don't want the network extension
+// code to see WireGuardAppError and tr(). Also, this extension is used only on macOS.
+
+extension TunnelConfiguration.ParseError: WireGuardAppError {
+ var alertText: AlertText {
+ switch self {
+ case .invalidLine(let line):
+ return (tr(format: "macAlertInvalidLine (%@)", String(line)), "")
+ case .noInterface:
+ return (tr("macAlertNoInterface"), "")
+ case .multipleInterfaces:
+ return (tr("macAlertMultipleInterfaces"), "")
+ case .interfaceHasNoPrivateKey:
+ return (tr("alertInvalidInterfaceMessagePrivateKeyRequired"), tr("alertInvalidInterfaceMessagePrivateKeyInvalid"))
+ case .interfaceHasInvalidPrivateKey:
+ return (tr("macAlertPrivateKeyInvalid"), tr("alertInvalidInterfaceMessagePrivateKeyInvalid"))
+ case .interfaceHasInvalidListenPort(let value):
+ return (tr(format: "macAlertListenPortInvalid (%@)", value), tr("alertInvalidInterfaceMessageListenPortInvalid"))
+ case .interfaceHasInvalidAddress(let value):
+ return (tr(format: "macAlertAddressInvalid (%@)", value), tr("alertInvalidInterfaceMessageAddressInvalid"))
+ case .interfaceHasInvalidDNS(let value):
+ return (tr(format: "macAlertDNSInvalid (%@)", value), tr("alertInvalidInterfaceMessageDNSInvalid"))
+ case .interfaceHasInvalidMTU(let value):
+ return (tr(format: "macAlertMTUInvalid (%@)", value), tr("alertInvalidInterfaceMessageMTUInvalid"))
+ case .interfaceHasUnrecognizedKey(let value):
+ return (tr(format: "macAlertUnrecognizedInterfaceKey (%@)", value), tr("macAlertInfoUnrecognizedInterfaceKey"))
+ case .peerHasNoPublicKey:
+ return (tr("alertInvalidPeerMessagePublicKeyRequired"), tr("alertInvalidPeerMessagePublicKeyInvalid"))
+ case .peerHasInvalidPublicKey:
+ return (tr("macAlertPublicKeyInvalid"), tr("alertInvalidPeerMessagePublicKeyInvalid"))
+ case .peerHasInvalidPreSharedKey:
+ return (tr("macAlertPreSharedKeyInvalid"), tr("alertInvalidPeerMessagePreSharedKeyInvalid"))
+ case .peerHasInvalidAllowedIP(let value):
+ return (tr(format: "macAlertAllowedIPInvalid (%@)", value), tr("alertInvalidPeerMessageAllowedIPsInvalid"))
+ case .peerHasInvalidEndpoint(let value):
+ return (tr(format: "macAlertEndpointInvalid (%@)", value), tr("alertInvalidPeerMessageEndpointInvalid"))
+ case .peerHasInvalidPersistentKeepAlive(let value):
+ return (tr(format: "macAlertPersistentKeepliveInvalid (%@)", value), tr("alertInvalidPeerMessagePersistentKeepaliveInvalid"))
+ case .peerHasUnrecognizedKey(let value):
+ return (tr(format: "macAlertUnrecognizedPeerKey (%@)", value), tr("macAlertInfoUnrecognizedPeerKey"))
+ case .multiplePeersWithSamePublicKey:
+ return (tr("alertInvalidPeerMessagePublicKeyDuplicated"), "")
+ }
+ }
+}