From 1e7401265676e79afbffb0396a0605726b93509e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 25 Mar 2023 12:16:52 +0530 Subject: [PATCH] fix: remove NoKeysProvided error We're making this invariant impossible in the code paths that hit it --- .../app/passwordstore/crypto/errors/CryptoException.kt | 3 --- .../app/passwordstore/crypto/PGPainlessCryptoHandler.kt | 5 ++--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/crypto-common/src/main/kotlin/app/passwordstore/crypto/errors/CryptoException.kt b/crypto-common/src/main/kotlin/app/passwordstore/crypto/errors/CryptoException.kt index 81bdf95f..cb8980bd 100644 --- a/crypto-common/src/main/kotlin/app/passwordstore/crypto/errors/CryptoException.kt +++ b/crypto-common/src/main/kotlin/app/passwordstore/crypto/errors/CryptoException.kt @@ -37,8 +37,5 @@ public sealed class CryptoHandlerException(message: String? = null, cause: Throw /** The passphrase provided for decryption was incorrect. */ public class IncorrectPassphraseException(cause: Throwable) : CryptoHandlerException(null, cause) -/** No keys were provided for encryption. */ -public class NoKeysProvided(message: String?) : CryptoHandlerException(message, null) - /** An unexpected error that cannot be mapped to a known type. */ public class UnknownError(cause: Throwable) : CryptoHandlerException(null, cause) diff --git a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt index e1084dec..2bf68401 100644 --- a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt +++ b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt @@ -7,7 +7,6 @@ package app.passwordstore.crypto import app.passwordstore.crypto.errors.CryptoHandlerException import app.passwordstore.crypto.errors.IncorrectPassphraseException -import app.passwordstore.crypto.errors.NoKeysProvided import app.passwordstore.crypto.errors.UnknownError import com.github.michaelbull.result.Result import com.github.michaelbull.result.mapError @@ -38,7 +37,7 @@ public class PGPainlessCryptoHandler @Inject constructor() : options: PGPDecryptOptions, ): Result = runCatching { - if (keys.isEmpty()) throw NoKeysProvided("No keys provided for encryption") + require(keys.isNotEmpty()) val keyringCollection = keys .map { key -> PGPainless.readKeyRing().secretKeyRing(key.contents) } @@ -68,7 +67,7 @@ public class PGPainlessCryptoHandler @Inject constructor() : options: PGPEncryptOptions, ): Result = runCatching { - if (keys.isEmpty()) throw NoKeysProvided("No keys provided for encryption") + require(keys.isNotEmpty()) val publicKeyRings = keys.mapNotNull(KeyUtils::tryParseKeyring).mapNotNull { keyRing -> when (keyRing) {