mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2025-02-08 00:42:03 +00:00
Parsing: Error on duplicate entries
This commit is contained in:
parent
3830499ac1
commit
bc9f050d7f
@ -30,6 +30,7 @@ extension TunnelConfiguration {
|
|||||||
case peerHasInvalidPersistentKeepAlive(String)
|
case peerHasInvalidPersistentKeepAlive(String)
|
||||||
case peerHasUnrecognizedKey(String)
|
case peerHasUnrecognizedKey(String)
|
||||||
case multiplePeersWithSamePublicKey
|
case multiplePeersWithSamePublicKey
|
||||||
|
case multipleEntriesForKey(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
//swiftlint:disable:next function_body_length cyclomatic_complexity
|
//swiftlint:disable:next function_body_length cyclomatic_complexity
|
||||||
@ -61,8 +62,12 @@ extension TunnelConfiguration {
|
|||||||
let key = keyWithCase.lowercased()
|
let key = keyWithCase.lowercased()
|
||||||
let value = line[line.index(equalsIndex, offsetBy: 1)...].trimmingCharacters(in: .whitespaces)
|
let value = line[line.index(equalsIndex, offsetBy: 1)...].trimmingCharacters(in: .whitespaces)
|
||||||
let keysWithMultipleEntriesAllowed: Set<String> = ["address", "allowedips", "dns"]
|
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
|
attributes[key] = presentValue + "," + value
|
||||||
|
} else {
|
||||||
|
throw ParseError.multipleEntriesForKey(keyWithCase)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
attributes[key] = value
|
attributes[key] = value
|
||||||
}
|
}
|
||||||
|
@ -281,3 +281,5 @@
|
|||||||
|
|
||||||
"macAlertUnrecognizedPeerKey (%@)" = "Peer contains unrecognized key '%@'";
|
"macAlertUnrecognizedPeerKey (%@)" = "Peer contains unrecognized key '%@'";
|
||||||
"macAlertInfoUnrecognizedPeerKey" = "Valid keys are: 'PublicKey', 'PresharedKey', 'AllowedIPs', 'Endpoint' and 'PersistentKeepalive'";
|
"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"))
|
return (tr(format: "macAlertUnrecognizedPeerKey (%@)", value), tr("macAlertInfoUnrecognizedPeerKey"))
|
||||||
case .multiplePeersWithSamePublicKey:
|
case .multiplePeersWithSamePublicKey:
|
||||||
return (tr("alertInvalidPeerMessagePublicKeyDuplicated"), "")
|
return (tr("alertInvalidPeerMessagePublicKeyDuplicated"), "")
|
||||||
|
case .multipleEntriesForKey(let value):
|
||||||
|
return (tr(format: "macAlertMultipleEntriesForKey (%@)", value), "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user