@@ -11,11 +11,9 @@ import app.passwordstore.crypto.PGPEncryptOptions
1111import app.passwordstore.crypto.PGPIdentifier
1212import app.passwordstore.crypto.PGPKeyManager
1313import app.passwordstore.crypto.PGPainlessCryptoHandler
14- import app.passwordstore.crypto.errors.CryptoHandlerException
1514import app.passwordstore.injection.prefs.SettingsPreferences
1615import app.passwordstore.util.coroutines.DispatcherProvider
1716import app.passwordstore.util.settings.PreferenceKeys
18- import com.github.michaelbull.result.Result
1917import com.github.michaelbull.result.filterValues
2018import com.github.michaelbull.result.map
2119import com.github.michaelbull.result.mapBoth
@@ -39,48 +37,34 @@ constructor(
3937 }
4038 }
4139
42- suspend fun decrypt (
43- password : String ,
44- identities : List <PGPIdentifier >,
45- message : ByteArrayInputStream ,
46- out : ByteArrayOutputStream ,
47- ) =
48- withContext(dispatcherProvider.io()) {
49- decryptPgp(password, identities, message, out ).map { out }
50- }
51-
5240 suspend fun isPasswordProtected (identifiers : List <PGPIdentifier >): Boolean {
5341 val keys = identifiers.map { pgpKeyManager.getKeyById(it) }.filterValues()
5442 return pgpCryptoHandler.isPassphraseProtected(keys)
5543 }
5644
57- suspend fun encrypt (
58- identities : List <PGPIdentifier >,
59- content : ByteArrayInputStream ,
60- out : ByteArrayOutputStream ,
61- ) = withContext(dispatcherProvider.io()) { encryptPgp(identities, content, out ).map { out } }
62-
63- private suspend fun decryptPgp (
45+ suspend fun decrypt (
6446 password : String ,
6547 identities : List <PGPIdentifier >,
6648 message : ByteArrayInputStream ,
6749 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- }
50+ ) =
51+ 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 }
55+ }
7356
74- private suspend fun encryptPgp (
57+ suspend fun encrypt (
7558 identities : List <PGPIdentifier >,
7659 content : ByteArrayInputStream ,
7760 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- }
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+ }
8670}
0 commit comments