Parsing: Error on duplicate entries
This commit is contained in:
parent
3830499ac1
commit
bc9f050d7f
|
@ -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) {
|
||||
if let presentValue = attributes[key] {
|
||||
if keysWithMultipleEntriesAllowed.contains(key) {
|
||||
attributes[key] = presentValue + "," + value
|
||||
} else {
|
||||
throw ParseError.multipleEntriesForKey(keyWithCase)
|
||||
}
|
||||
} else {
|
||||
attributes[key] = value
|
||||
}
|
||||
|
|
|
@ -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 '%@'";
|
||||
|
|
|
@ -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), "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue