aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/ViewController
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-09 00:41:36 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:35 +0530
commit80977b95dec7224519c0a9b775f4fe4a203f6966 (patch)
treee4c848d6b5e49213263ada66fb727f3d6c7eb5ad /WireGuard/WireGuard/UI/macOS/ViewController
parentHighlighter: Report each key type separately (diff)
downloadwireguard-apple-80977b95dec7224519c0a9b775f4fe4a203f6966.tar.xz
wireguard-apple-80977b95dec7224519c0a9b775f4fe4a203f6966.zip
macOS: Edit view: Update public key as you edit
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/macOS/ViewController')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift17
1 files changed, 15 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift
index 8143787..d8dbbd2 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift
@@ -17,7 +17,7 @@ class TunnelEditViewController: NSViewController {
return publicKeyRow
}()
- let textView: NSTextView = {
+ let textView: ConfTextView = {
let textView = ConfTextView()
let minWidth: CGFloat = 120
let minHeight: CGFloat = 60
@@ -62,6 +62,8 @@ class TunnelEditViewController: NSViewController {
let tunnelsManager: TunnelsManager
let tunnel: TunnelContainer?
+ var textViewObservationToken: AnyObject?
+
init(tunnelsManager: TunnelsManager, tunnel: TunnelContainer?) {
self.tunnelsManager = tunnelsManager
self.tunnel = tunnel
@@ -75,8 +77,19 @@ class TunnelEditViewController: NSViewController {
override func loadView() {
if let tunnel = tunnel, let tunnelConfiguration = tunnel.tunnelConfiguration {
nameRow.value = tunnel.name
- publicKeyRow.value = tunnelConfiguration.interface.publicKey.base64EncodedString()
textView.string = tunnelConfiguration.asWgQuickConfig()
+ publicKeyRow.value = tunnelConfiguration.interface.publicKey.base64EncodedString()
+ textView.privateKeyString = tunnelConfiguration.interface.privateKey.base64EncodedString()
+ textViewObservationToken = textView.observe(\.privateKeyString) { [weak publicKeyRow] textView, _ in
+ if let privateKeyString = textView.privateKeyString,
+ let privateKey = Data(base64Encoded: privateKeyString),
+ privateKey.count == TunnelConfiguration.keyLength {
+ let publicKey = Curve25519.generatePublicKey(fromPrivateKey: privateKey)
+ publicKeyRow?.value = publicKey.base64EncodedString()
+ } else {
+ publicKeyRow?.value = ""
+ }
+ }
}
scrollView.documentView = textView