aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard/Shared')
-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") }
}
}