aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/TunnelViewModel.swift
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/WireGuard/UI/TunnelViewModel.swift
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 '')
-rw-r--r--WireGuard/WireGuard/UI/TunnelViewModel.swift8
1 files changed, 4 insertions, 4 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift
index de14ad5..92a1a64 100644
--- a/WireGuard/WireGuard/UI/TunnelViewModel.swift
+++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift
@@ -65,7 +65,7 @@ class TunnelViewModel {
if (field == .privateKey) {
if (stringValue.count == TunnelViewModel.keyLengthInBase64),
let privateKey = Data(base64Encoded: stringValue),
- privateKey.count == 32 {
+ privateKey.count == TunnelConfiguration.keyLength {
let publicKey = Curve25519.generatePublicKey(fromPrivateKey: privateKey)
scratchpad[.publicKey] = publicKey.base64EncodedString()
} else {
@@ -109,7 +109,7 @@ class TunnelViewModel {
fieldsWithError.insert(.privateKey)
return .error("Interface's private key is required")
}
- guard let privateKey = Data(base64Encoded: privateKeyString), privateKey.count == 32 else {
+ guard let privateKey = Data(base64Encoded: privateKeyString), privateKey.count == TunnelConfiguration.keyLength else {
fieldsWithError.insert(.privateKey)
return .error("Interface's private key must be a 32-byte key in base64 encoding")
}
@@ -247,14 +247,14 @@ class TunnelViewModel {
fieldsWithError.insert(.publicKey)
return .error("Peer's public key is required")
}
- guard let publicKey = Data(base64Encoded: publicKeyString), publicKey.count == 32 else {
+ guard let publicKey = Data(base64Encoded: publicKeyString), publicKey.count == TunnelConfiguration.keyLength else {
fieldsWithError.insert(.publicKey)
return .error("Peer's public key must be a 32-byte key in base64 encoding")
}
var config = PeerConfiguration(publicKey: publicKey)
var errorMessages: [String] = []
if let preSharedKeyString = scratchpad[.preSharedKey] {
- if let preSharedKey = Data(base64Encoded: preSharedKeyString), preSharedKey.count == 32 {
+ if let preSharedKey = Data(base64Encoded: preSharedKeyString), preSharedKey.count == TunnelConfiguration.keyLength {
config.preSharedKey = preSharedKey
} else {
fieldsWithError.insert(.preSharedKey)