From: Roopesh Chander Date: Tue, 8 Jan 2019 13:58:38 +0000 (+0530) Subject: Parsing: Error on duplicate entries X-Git-Tag: 0.0.20190207-1~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc03c635c1e85b306c456cd9517201d05bf3d187;p=thirdparty%2Fwireguard-apple.git Parsing: Error on duplicate entries Signed-off-by: Roopesh Chander --- diff --git a/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift b/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift index e438e29..48c88b0 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 = ["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 } diff --git a/WireGuard/WireGuard/Base.lproj/Localizable.strings b/WireGuard/WireGuard/Base.lproj/Localizable.strings index e2a7295..3cfe1fc 100644 --- a/WireGuard/WireGuard/Base.lproj/Localizable.strings +++ b/WireGuard/WireGuard/Base.lproj/Localizable.strings @@ -281,3 +281,5 @@ "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 '%@'"; diff --git a/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift b/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift index 4a1c890..a85df22 100644 --- a/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift +++ b/WireGuard/WireGuard/UI/macOS/ParseError+WireGuardAppError.swift @@ -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), "") } } }