summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-09-05 20:36:19 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-09-05 22:49:37 +0530
commite6675d989d8bc21a392c73d2597a8f3507149926 (patch)
treefe524587740ccff1c10b5afa18cd7b06c41f65b8
parentee6fd10ea61e0f4789bc255418993ad59df44b34 (diff)
SshjSessionFactory: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjSessionFactory.kt7
1 files changed, 4 insertions, 3 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjSessionFactory.kt b/app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjSessionFactory.kt
index 58002af0..a507d50b 100644
--- a/app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjSessionFactory.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/git/sshj/SshjSessionFactory.kt
@@ -8,11 +8,12 @@ import android.util.Base64
import androidx.fragment.app.FragmentActivity
import com.github.ajalt.timberkt.d
import com.github.ajalt.timberkt.w
+import com.github.michaelbull.result.getOrElse
+import com.github.michaelbull.result.runCatching
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
-import java.security.GeneralSecurityException
import java.util.concurrent.TimeUnit
import kotlin.coroutines.Continuation
import kotlin.coroutines.suspendCoroutine
@@ -80,9 +81,9 @@ class SshjSessionFactory(private val authData: SshAuthData, private val hostKeyF
private fun makeTofuHostKeyVerifier(hostKeyFile: File): HostKeyVerifier {
if (!hostKeyFile.exists()) {
return HostKeyVerifier { _, _, key ->
- val digest = try {
+ val digest = runCatching {
SecurityUtils.getMessageDigest("SHA-256")
- } catch (e: GeneralSecurityException) {
+ }.getOrElse { e ->
throw SSHRuntimeException(e)
}
digest.update(PlainBuffer().putPublicKey(key).compactData)