Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit cb22561

Browse files
committed
Revert "refactor(app): inline pointless methods in CryptoRepository"
This reverts commit b05a6d4.
1 parent a2ede93 commit cb22561

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import app.passwordstore.crypto.PGPEncryptOptions
1111
import app.passwordstore.crypto.PGPIdentifier
1212
import app.passwordstore.crypto.PGPKeyManager
1313
import app.passwordstore.crypto.PGPainlessCryptoHandler
14+
import app.passwordstore.crypto.errors.CryptoHandlerException
1415
import app.passwordstore.injection.prefs.SettingsPreferences
1516
import app.passwordstore.util.coroutines.DispatcherProvider
1617
import app.passwordstore.util.settings.PreferenceKeys
18+
import com.github.michaelbull.result.Result
1719
import com.github.michaelbull.result.filterValues
1820
import com.github.michaelbull.result.map
1921
import com.github.michaelbull.result.mapBoth
@@ -37,34 +39,48 @@ constructor(
3739
}
3840
}
3941

40-
suspend fun isPasswordProtected(identifiers: List<PGPIdentifier>): Boolean {
41-
val keys = identifiers.map { pgpKeyManager.getKeyById(it) }.filterValues()
42-
return pgpCryptoHandler.isPassphraseProtected(keys)
43-
}
44-
4542
suspend fun decrypt(
4643
password: String,
4744
identities: List<PGPIdentifier>,
4845
message: ByteArrayInputStream,
4946
out: ByteArrayOutputStream,
5047
) =
5148
withContext(dispatcherProvider.io()) {
52-
val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
53-
val decryptionOptions = PGPDecryptOptions.Builder().build()
54-
pgpCryptoHandler.decrypt(keys, password, message, out, decryptionOptions).map { out }
49+
decryptPgp(password, identities, message, out).map { out }
5550
}
5651

52+
suspend fun isPasswordProtected(identifiers: List<PGPIdentifier>): Boolean {
53+
val keys = identifiers.map { pgpKeyManager.getKeyById(it) }.filterValues()
54+
return pgpCryptoHandler.isPassphraseProtected(keys)
55+
}
56+
5757
suspend fun encrypt(
5858
identities: List<PGPIdentifier>,
5959
content: ByteArrayInputStream,
6060
out: ByteArrayOutputStream,
61-
) =
62-
withContext(dispatcherProvider.io()) {
63-
val encryptionOptions =
64-
PGPEncryptOptions.Builder()
65-
.withAsciiArmor(settings.getBoolean(PreferenceKeys.ASCII_ARMOR, false))
66-
.build()
67-
val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
68-
pgpCryptoHandler.encrypt(keys, content, out, encryptionOptions).map { out }
69-
}
61+
) = withContext(dispatcherProvider.io()) { encryptPgp(identities, content, out).map { out } }
62+
63+
private suspend fun decryptPgp(
64+
password: String,
65+
identities: List<PGPIdentifier>,
66+
message: ByteArrayInputStream,
67+
out: ByteArrayOutputStream,
68+
): Result<Unit, CryptoHandlerException> {
69+
val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
70+
val decryptionOptions = PGPDecryptOptions.Builder().build()
71+
return pgpCryptoHandler.decrypt(keys, password, message, out, decryptionOptions)
72+
}
73+
74+
private suspend fun encryptPgp(
75+
identities: List<PGPIdentifier>,
76+
content: ByteArrayInputStream,
77+
out: ByteArrayOutputStream,
78+
): Result<Unit, CryptoHandlerException> {
79+
val encryptionOptions =
80+
PGPEncryptOptions.Builder()
81+
.withAsciiArmor(settings.getBoolean(PreferenceKeys.ASCII_ARMOR, false))
82+
.build()
83+
val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
84+
return pgpCryptoHandler.encrypt(keys, content, out, encryptionOptions)
85+
}
7086
}

0 commit comments

Comments
 (0)