]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Parsing: Error on duplicate entries
authorRoopesh Chander <roop@roopc.net>
Tue, 8 Jan 2019 13:58:38 +0000 (19:28 +0530)
committerRoopesh Chander <roop@roopc.net>
Mon, 14 Jan 2019 09:22:34 +0000 (14:52 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift
WireGuard/WireGuard/Base.lproj/Localizable.strings
WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift

index e438e29f1f81ba6e4cd5a235a5797efbf913838d..48c88b02626474b3c660239549e95b33c368e97f 100644 (file)
@@ -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
                 }
index e2a7295051fa448eb65698760732974748e571d6..3cfe1fc7513d627703db701fffc02558efe9c318 100644 (file)
 
 "macAlertUnrecognizedPeerKey (%@)" = "Peer contains unrecognized key '%@'";
 "macAlertInfoUnrecognizedPeerKey" = "Valid keys are: 'PublicKey', 'PresharedKey', 'AllowedIPs', 'Endpoint' and 'PersistentKeepalive'";
+
+"macAlertMultipleEntriesForKey (%@)" = "There should be only one entry per section for key '%@'";
index 4a1c890b7bd250617be0e23c630bec6790d39d46..a85df22f42893e8d90258d9f02ba02e004bc5d51 100644 (file)
@@ -45,6 +45,8 @@ extension TunnelConfiguration.ParseError: WireGuardAppError {
             return (tr(format: "macAlertUnrecognizedPeerKey (%@)", value), tr("macAlertInfoUnrecognizedPeerKey"))
         case .multiplePeersWithSamePublicKey:
             return (tr("alertInvalidPeerMessagePublicKeyDuplicated"), "")
+        case .multipleEntriesForKey(let value):
+            return (tr(format: "macAlertMultipleEntriesForKey (%@)", value), "")
         }
     }
 }