fix: remove NoKeysProvided error

We're making this invariant impossible in the code paths that hit it
This commit is contained in:
Harsh Shandilya 2023-03-25 12:16:52 +05:30
parent e2900c26de
commit 1e74012656
No known key found for this signature in database
2 changed files with 2 additions and 6 deletions

View file

@ -37,8 +37,5 @@ public sealed class CryptoHandlerException(message: String? = null, cause: Throw
/** The passphrase provided for decryption was incorrect. */ /** The passphrase provided for decryption was incorrect. */
public class IncorrectPassphraseException(cause: Throwable) : CryptoHandlerException(null, cause) 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. */ /** An unexpected error that cannot be mapped to a known type. */
public class UnknownError(cause: Throwable) : CryptoHandlerException(null, cause) public class UnknownError(cause: Throwable) : CryptoHandlerException(null, cause)

View file

@ -7,7 +7,6 @@ package app.passwordstore.crypto
import app.passwordstore.crypto.errors.CryptoHandlerException import app.passwordstore.crypto.errors.CryptoHandlerException
import app.passwordstore.crypto.errors.IncorrectPassphraseException import app.passwordstore.crypto.errors.IncorrectPassphraseException
import app.passwordstore.crypto.errors.NoKeysProvided
import app.passwordstore.crypto.errors.UnknownError import app.passwordstore.crypto.errors.UnknownError
import com.github.michaelbull.result.Result import com.github.michaelbull.result.Result
import com.github.michaelbull.result.mapError import com.github.michaelbull.result.mapError
@ -38,7 +37,7 @@ public class PGPainlessCryptoHandler @Inject constructor() :
options: PGPDecryptOptions, options: PGPDecryptOptions,
): Result<Unit, CryptoHandlerException> = ): Result<Unit, CryptoHandlerException> =
runCatching { runCatching {
if (keys.isEmpty()) throw NoKeysProvided("No keys provided for encryption") require(keys.isNotEmpty())
val keyringCollection = val keyringCollection =
keys keys
.map { key -> PGPainless.readKeyRing().secretKeyRing(key.contents) } .map { key -> PGPainless.readKeyRing().secretKeyRing(key.contents) }
@ -68,7 +67,7 @@ public class PGPainlessCryptoHandler @Inject constructor() :
options: PGPEncryptOptions, options: PGPEncryptOptions,
): Result<Unit, CryptoHandlerException> = ): Result<Unit, CryptoHandlerException> =
runCatching { runCatching {
if (keys.isEmpty()) throw NoKeysProvided("No keys provided for encryption") require(keys.isNotEmpty())
val publicKeyRings = val publicKeyRings =
keys.mapNotNull(KeyUtils::tryParseKeyring).mapNotNull { keyRing -> keys.mapNotNull(KeyUtils::tryParseKeyring).mapNotNull { keyRing ->
when (keyRing) { when (keyRing) {