aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared/Model
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-08 18:52:11 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-09 14:07:03 +0530
commit60e13ddbf6e0d9fc03b57806043dbf0266a8cf70 (patch)
tree6a77e77358b5d9b25231d70058732aafaf7b486f /WireGuard/Shared/Model
parentTunnelsManager: Observe status for all tunnels in one block (diff)
downloadwireguard-apple-60e13ddbf6e0d9fc03b57806043dbf0266a8cf70.tar.xz
wireguard-apple-60e13ddbf6e0d9fc03b57806043dbf0266a8cf70.zip
Model: Declare keyLength constant and use that wherever applicable
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/Shared/Model')
-rw-r--r--WireGuard/Shared/Model/Configuration.swift9
1 files changed, 6 insertions, 3 deletions
diff --git a/WireGuard/Shared/Model/Configuration.swift b/WireGuard/Shared/Model/Configuration.swift
index 41ff7bc0..d2680cbe 100644
--- a/WireGuard/Shared/Model/Configuration.swift
+++ b/WireGuard/Shared/Model/Configuration.swift
@@ -7,6 +7,9 @@ import Foundation
final class TunnelConfiguration: Codable {
var interface: InterfaceConfiguration
let peers: [PeerConfiguration]
+
+ static let keyLength: Int = 32
+
init(interface: InterfaceConfiguration, peers: [PeerConfiguration]) {
self.interface = interface
self.peers = peers
@@ -32,7 +35,7 @@ struct InterfaceConfiguration: Codable {
self.name = name
self.privateKey = privateKey
if (name.isEmpty) { fatalError("Empty name") }
- if (privateKey.count != 32) { fatalError("Invalid private key") }
+ if (privateKey.count != TunnelConfiguration.keyLength) { fatalError("Invalid private key") }
}
}
@@ -42,7 +45,7 @@ struct PeerConfiguration: Codable {
var preSharedKey: Data? {
didSet(value) {
if let value = value {
- if (value.count != 32) { fatalError("Invalid preshared key") }
+ if (value.count != TunnelConfiguration.keyLength) { fatalError("Invalid preshared key") }
}
}
}
@@ -52,6 +55,6 @@ struct PeerConfiguration: Codable {
init(publicKey: Data) {
self.publicKey = publicKey
- if (publicKey.count != 32) { fatalError("Invalid public key") }
+ if (publicKey.count != TunnelConfiguration.keyLength) { fatalError("Invalid public key") }
}
}