@@ -744,11 +744,7 @@ class SshConnection(
744744 setMethodSpecificFields(noneAuth)
745745 }
746746
747- var noneResult = channel.receive()
748- while (noneResult is InternalAuthResult .Banner ) {
749- handler.onBanner(noneResult.message)
750- noneResult = channel.receive()
751- }
747+ val noneResult = receiveAuthResult(channel, handler)
752748 if (noneResult is InternalAuthResult .Success ) return PublicAuthResult .Success
753749 if (noneResult !is InternalAuthResult .Failure ) return PublicAuthResult .Error (" Unexpected response to 'none' auth: $noneResult " )
754750
@@ -823,12 +819,7 @@ class SshConnection(
823819 }
824820 setMethodSpecificFields(pubkeyAuth)
825821 }
826- var response = channel.receive()
827- while (response is InternalAuthResult .Banner ) {
828- handler.onBanner(response.message)
829- response = channel.receive()
830- }
831- return response
822+ return receiveAuthResult(channel, handler)
832823 }
833824
834825 private suspend fun signPublicKey (
@@ -881,11 +872,7 @@ class SshConnection(
881872 }
882873 }
883874
884- var response = channel.receive()
885- while (response is InternalAuthResult .Banner ) {
886- handler.onBanner(response.message)
887- response = channel.receive()
888- }
875+ val response = receiveAuthResult(channel, handler)
889876 return when (response) {
890877 is InternalAuthResult .Success -> true
891878 else -> false
@@ -965,11 +952,7 @@ class SshConnection(
965952 setMethodSpecificFields(passAuth)
966953 }
967954
968- var response = channel.receive()
969- while (response is InternalAuthResult .Banner ) {
970- handler.onBanner(response.message)
971- response = channel.receive()
972- }
955+ val response = receiveAuthResult(channel, handler)
973956 return when (val result = response) {
974957 is InternalAuthResult .Success -> true
975958
@@ -982,6 +965,18 @@ class SshConnection(
982965 }
983966 }
984967
968+ private suspend fun receiveAuthResult (
969+ channel : Channel <InternalAuthResult >,
970+ handler : AuthHandler ,
971+ ): InternalAuthResult {
972+ var result = channel.receive()
973+ while (result is InternalAuthResult .Banner ) {
974+ handler.onBanner(result.message)
975+ result = channel.receive()
976+ }
977+ return result
978+ }
979+
985980 private suspend fun sendAuthRequest (
986981 username : String ,
987982 method : String ,
0 commit comments