diff options
author | Roopesh Chander <roop@roopc.net> | 2018-11-10 17:02:30 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2018-11-10 17:02:30 +0530 |
commit | 290f83d5ef4d26e11d0b6eaccd47fcda7d359ae3 (patch) | |
tree | 8f1c9edb5f97bfd327bfa6b84e044ebba71d41e5 /WireGuard/Shared/Model/Configuration.swift | |
parent | VPN: When activating while another tunnel is active, deactivate the other tunnel (diff) | |
download | wireguard-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 '')
-rw-r--r-- | WireGuard/Shared/Model/Configuration.swift | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/WireGuard/Shared/Model/Configuration.swift b/WireGuard/Shared/Model/Configuration.swift index cbe4271..3e661e6 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") + } } } |