From ddad89b0e284a8657b9a3c83c81d119dff8c0e19 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Thu, 3 Jul 2025 12:36:27 +0100 Subject: [PATCH] switched while loop out for a guard to break the loop --- ShhShell/SSH/SSHHandler.swift | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/ShhShell/SSH/SSHHandler.swift b/ShhShell/SSH/SSHHandler.swift index 3ab65f5..3d74f2f 100644 --- a/ShhShell/SSH/SSHHandler.swift +++ b/ShhShell/SSH/SSHHandler.swift @@ -71,26 +71,25 @@ class SSHHandler: @unchecked Sendable, ObservableObject { //TODO: check hostkey - while state != .authorized { - for method in getAuthMethods() { - switch method { - case .password: - do { try authWithPw() } catch { - state = .authFailed - print("pw auth error") - print(error.localizedDescription) - } - case .publickey: - do { try authWithPubkey() } catch { - state = .authFailed - print("error with pubkey auth") - print(error.localizedDescription) - } - case .hostbased: - disconnect() - case .interactive: - disconnect() + for method in getAuthMethods() { + guard state != .authorized else { break } + switch method { + case .password: + do { try authWithPw() } catch { + state = .authFailed + print("pw auth error") + print(error.localizedDescription) } + case .publickey: + do { try authWithPubkey() } catch { + state = .authFailed + print("error with pubkey auth") + print(error.localizedDescription) + } + case .hostbased: + disconnect() + case .interactive: + disconnect() } }