summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-09-28 23:35:54 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2024-09-28 23:35:54 +0530
commit7e1ed55ab7f4650ac0825e63bd7d2defd968faba (patch)
treed60c4b2f1cb8330a5bc3160d93704a9c7b9e8d36
parent04f4b9804f10e4724bac22d40bf01711ff708533 (diff)
Reapply "refactor(app): inline pointless methods in `CryptoRepository`"
This reverts commit cb22561878d4358dba974c16ba9a05cc693d411a.
-rw-r--r--app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt50
1 files changed, 17 insertions, 33 deletions
diff --git a/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt b/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt
index cd54dac2..eb858006 100644
--- a/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt
+++ b/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt
@@ -11,11 +11,9 @@ import app.passwordstore.crypto.PGPEncryptOptions
import app.passwordstore.crypto.PGPIdentifier
import app.passwordstore.crypto.PGPKeyManager
import app.passwordstore.crypto.PGPainlessCryptoHandler
-import app.passwordstore.crypto.errors.CryptoHandlerException
import app.passwordstore.injection.prefs.SettingsPreferences
import app.passwordstore.util.coroutines.DispatcherProvider
import app.passwordstore.util.settings.PreferenceKeys
-import com.github.michaelbull.result.Result
import com.github.michaelbull.result.filterValues
import com.github.michaelbull.result.map
import com.github.michaelbull.result.mapBoth
@@ -39,48 +37,34 @@ constructor(
}
}
- suspend fun decrypt(
- password: String,
- identities: List<PGPIdentifier>,
- message: ByteArrayInputStream,
- out: ByteArrayOutputStream,
- ) =
- withContext(dispatcherProvider.io()) {
- decryptPgp(password, identities, message, out).map { out }
- }
-
suspend fun isPasswordProtected(identifiers: List<PGPIdentifier>): Boolean {
val keys = identifiers.map { pgpKeyManager.getKeyById(it) }.filterValues()
return pgpCryptoHandler.isPassphraseProtected(keys)
}
- suspend fun encrypt(
- identities: List<PGPIdentifier>,
- content: ByteArrayInputStream,
- out: ByteArrayOutputStream,
- ) = withContext(dispatcherProvider.io()) { encryptPgp(identities, content, out).map { out } }
-
- private suspend fun decryptPgp(
+ suspend fun decrypt(
password: String,
identities: List<PGPIdentifier>,
message: ByteArrayInputStream,
out: ByteArrayOutputStream,
- ): Result<Unit, CryptoHandlerException> {
- val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
- val decryptionOptions = PGPDecryptOptions.Builder().build()
- return pgpCryptoHandler.decrypt(keys, password, message, out, decryptionOptions)
- }
+ ) =
+ withContext(dispatcherProvider.io()) {
+ val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
+ val decryptionOptions = PGPDecryptOptions.Builder().build()
+ pgpCryptoHandler.decrypt(keys, password, message, out, decryptionOptions).map { out }
+ }
- private suspend fun encryptPgp(
+ suspend fun encrypt(
identities: List<PGPIdentifier>,
content: ByteArrayInputStream,
out: ByteArrayOutputStream,
- ): Result<Unit, CryptoHandlerException> {
- val encryptionOptions =
- PGPEncryptOptions.Builder()
- .withAsciiArmor(settings.getBoolean(PreferenceKeys.ASCII_ARMOR, false))
- .build()
- val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
- return pgpCryptoHandler.encrypt(keys, content, out, encryptionOptions)
- }
+ ) =
+ withContext(dispatcherProvider.io()) {
+ val encryptionOptions =
+ PGPEncryptOptions.Builder()
+ .withAsciiArmor(settings.getBoolean(PreferenceKeys.ASCII_ARMOR, false))
+ .build()
+ val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
+ pgpCryptoHandler.encrypt(keys, content, out, encryptionOptions).map { out }
+ }
}