aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-08 19:28:38 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:34 +0530
commitfc03c635c1e85b306c456cd9517201d05bf3d187 (patch)
treefd31c6b0b1d38db14565e86be6d484d15ce96021 /WireGuard/Shared
parentmacOS: Edit view: Validate and save (diff)
downloadwireguard-apple-fc03c635c1e85b306c456cd9517201d05bf3d187.tar.xz
wireguard-apple-fc03c635c1e85b306c456cd9517201d05bf3d187.zip
Parsing: Error on duplicate entries
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/Shared')
-rw-r--r--WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift9
1 files changed, 7 insertions, 2 deletions
diff --git a/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift b/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift
index e438e29f..48c88b02 100644
--- a/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift
+++ b/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift
@@ -30,6 +30,7 @@ extension TunnelConfiguration {
case peerHasInvalidPersistentKeepAlive(String)
case peerHasUnrecognizedKey(String)
case multiplePeersWithSamePublicKey
+ case multipleEntriesForKey(String)
}
//swiftlint:disable:next function_body_length cyclomatic_complexity
@@ -61,8 +62,12 @@ extension TunnelConfiguration {
let key = keyWithCase.lowercased()
let value = line[line.index(equalsIndex, offsetBy: 1)...].trimmingCharacters(in: .whitespaces)
let keysWithMultipleEntriesAllowed: Set<String> = ["address", "allowedips", "dns"]
- if let presentValue = attributes[key], keysWithMultipleEntriesAllowed.contains(key) {
- attributes[key] = presentValue + "," + value
+ if let presentValue = attributes[key] {
+ if keysWithMultipleEntriesAllowed.contains(key) {
+ attributes[key] = presentValue + "," + value
+ } else {
+ throw ParseError.multipleEntriesForKey(keyWithCase)
+ }
} else {
attributes[key] = value
}