diff options
Diffstat (limited to 'WireGuard/WireGuard/UI/TunnelViewModel.swift')
-rw-r--r-- | WireGuard/WireGuard/UI/TunnelViewModel.swift | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift index b28abeb..e7ab12d 100644 --- a/WireGuard/WireGuard/UI/TunnelViewModel.swift +++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift @@ -27,6 +27,8 @@ class TunnelViewModel { case deletePeer = "Delete peer" } + static let keyLengthInBase64 = 44 + class InterfaceData { var scratchpad: [InterfaceField: String] = [:] var fieldsWithError: Set<InterfaceField> = [] @@ -53,6 +55,16 @@ class TunnelViewModel { } else { scratchpad[field] = stringValue } + if (field == .privateKey) { + if (stringValue.count == TunnelViewModel.keyLengthInBase64), + let privateKey = Data(base64Encoded: stringValue), + privateKey.count == 32 { + let publicKey = Curve25519.generatePublicKey(fromPrivateKey: privateKey) + scratchpad[.publicKey] = publicKey.base64EncodedString() + } else { + scratchpad.removeValue(forKey: .publicKey) + } + } } } |