case peerHasInvalidPersistentKeepAlive(String)
case peerHasUnrecognizedKey(String)
case multiplePeersWithSamePublicKey
+ case multipleEntriesForKey(String)
}
//swiftlint:disable:next function_body_length cyclomatic_complexity
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
}
"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 '%@'";
return (tr(format: "macAlertUnrecognizedPeerKey (%@)", value), tr("macAlertInfoUnrecognizedPeerKey"))
case .multiplePeersWithSamePublicKey:
return (tr("alertInvalidPeerMessagePublicKeyDuplicated"), "")
+ case .multipleEntriesForKey(let value):
+ return (tr(format: "macAlertMultipleEntriesForKey (%@)", value), "")
}
}
}