summaryrefslogtreecommitdiff
path: root/crypto-pgpainless/src
diff options
context:
space:
mode:
authorAditya Wasan <adityawasan55@gmail.com>2022-03-23 18:18:06 +0530
committerGitHub <noreply@github.com>2022-03-23 12:48:06 +0000
commit9c9616d04752e5b47966917f8648fdbb62e05ba9 (patch)
tree25ec60c1fcbe1b8e47e387d3c766fbfa06370b95 /crypto-pgpainless/src
parentcf3ae17b8461d9c94e38760e582950f7f26da855 (diff)
fix: ignore `CancellationException` in suspend functions (#1794)
* fix: ignore `CancellationException` in suspend functions Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * build(coroutine-utils): use `api` instead of `implementation` Co-authored-by: Harsh Shandilya <me@msfjarvis.dev> Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'crypto-pgpainless/src')
-rw-r--r--crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt14
1 files changed, 7 insertions, 7 deletions
diff --git a/crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt b/crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt
index adcce22b..8c54d516 100644
--- a/crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt
+++ b/crypto-pgpainless/src/main/kotlin/dev/msfjarvis/aps/crypto/PGPKeyManager.kt
@@ -8,9 +8,9 @@ package dev.msfjarvis.aps.crypto
import androidx.annotation.VisibleForTesting
import com.github.michaelbull.result.Result
-import com.github.michaelbull.result.runCatching
import dev.msfjarvis.aps.crypto.KeyUtils.tryGetId
import dev.msfjarvis.aps.crypto.KeyUtils.tryParseKeyring
+import dev.msfjarvis.aps.util.coroutines.runSuspendCatching
import java.io.File
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
@@ -28,7 +28,7 @@ constructor(
override suspend fun addKey(key: PGPKey, replace: Boolean): Result<PGPKey, Throwable> =
withContext(dispatcher) {
- runCatching {
+ runSuspendCatching {
if (!keyDirExists()) throw KeyManagerException.KeyDirectoryUnavailableException
if (tryParseKeyring(key) == null) throw KeyManagerException.InvalidKeyException
val keyFile = File(keyDir, "${tryGetId(key)}.$KEY_EXTENSION")
@@ -49,7 +49,7 @@ constructor(
override suspend fun removeKey(key: PGPKey): Result<PGPKey, Throwable> =
withContext(dispatcher) {
- runCatching {
+ runSuspendCatching {
if (!keyDirExists()) throw KeyManagerException.KeyDirectoryUnavailableException
if (tryParseKeyring(key) == null) throw KeyManagerException.InvalidKeyException
val keyFile = File(keyDir, "${tryGetId(key)}.$KEY_EXTENSION")
@@ -63,7 +63,7 @@ constructor(
override suspend fun getKeyById(id: GpgIdentifier): Result<PGPKey, Throwable> =
withContext(dispatcher) {
- runCatching {
+ runSuspendCatching {
if (!keyDirExists()) throw KeyManagerException.KeyDirectoryUnavailableException
val keyFiles = keyDir.listFiles()
if (keyFiles.isNullOrEmpty()) throw KeyManagerException.NoKeysAvailableException
@@ -89,7 +89,7 @@ constructor(
}
if (matchResult != null) {
- return@runCatching matchResult
+ return@runSuspendCatching matchResult
}
throw KeyManagerException.KeyNotFoundException("$id")
@@ -98,10 +98,10 @@ constructor(
override suspend fun getAllKeys(): Result<List<PGPKey>, Throwable> =
withContext(dispatcher) {
- runCatching {
+ runSuspendCatching {
if (!keyDirExists()) throw KeyManagerException.KeyDirectoryUnavailableException
val keyFiles = keyDir.listFiles()
- if (keyFiles.isNullOrEmpty()) return@runCatching emptyList()
+ if (keyFiles.isNullOrEmpty()) return@runSuspendCatching emptyList()
keyFiles.map { keyFile -> PGPKey(keyFile.readBytes()) }.toList()
}
}