aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared/Model
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-10 17:02:30 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-10 17:02:30 +0530
commit290f83d5ef4d26e11d0b6eaccd47fcda7d359ae3 (patch)
tree8f1c9edb5f97bfd327bfa6b84e044ebba71d41e5 /WireGuard/Shared/Model
parentVPN: When activating while another tunnel is active, deactivate the other tunnel (diff)
downloadwireguard-apple-290f83d5ef4d26e11d0b6eaccd47fcda7d359ae3.tar.xz
wireguard-apple-290f83d5ef4d26e11d0b6eaccd47fcda7d359ae3.zip
Model: Ensure that a TunnelConfiguration always has a valid array of peers
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/Shared/Model')
-rw-r--r--WireGuard/Shared/Model/Configuration.swift11
1 files changed, 9 insertions, 2 deletions
diff --git a/WireGuard/Shared/Model/Configuration.swift b/WireGuard/Shared/Model/Configuration.swift
index cbe42712..3e661e61 100644
--- a/WireGuard/Shared/Model/Configuration.swift
+++ b/WireGuard/Shared/Model/Configuration.swift
@@ -6,9 +6,16 @@ import Foundation
@available(OSX 10.14, iOS 12.0, *)
class TunnelConfiguration: Codable {
var interface: InterfaceConfiguration
- var peers: [PeerConfiguration] = []
- init(interface: InterfaceConfiguration) {
+ let peers: [PeerConfiguration]
+ init(interface: InterfaceConfiguration, peers: [PeerConfiguration]) {
self.interface = interface
+ self.peers = peers
+
+ let peerPublicKeysArray = peers.map { $0.publicKey }
+ let peerPublicKeysSet = Set<Data>(peerPublicKeysArray)
+ if (peerPublicKeysArray.count != peerPublicKeysSet.count) {
+ fatalError("Two or more peers cannot have the same public key")
+ }
}
}