@@ -11,11 +11,9 @@ import app.passwordstore.crypto.PGPEncryptOptions
11
11
import app.passwordstore.crypto.PGPIdentifier
12
12
import app.passwordstore.crypto.PGPKeyManager
13
13
import app.passwordstore.crypto.PGPainlessCryptoHandler
14
- import app.passwordstore.crypto.errors.CryptoHandlerException
15
14
import app.passwordstore.injection.prefs.SettingsPreferences
16
15
import app.passwordstore.util.coroutines.DispatcherProvider
17
16
import app.passwordstore.util.settings.PreferenceKeys
18
- import com.github.michaelbull.result.Result
19
17
import com.github.michaelbull.result.filterValues
20
18
import com.github.michaelbull.result.map
21
19
import com.github.michaelbull.result.mapBoth
@@ -39,48 +37,34 @@ constructor(
39
37
}
40
38
}
41
39
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
-
52
40
suspend fun isPasswordProtected (identifiers : List <PGPIdentifier >): Boolean {
53
41
val keys = identifiers.map { pgpKeyManager.getKeyById(it) }.filterValues()
54
42
return pgpCryptoHandler.isPassphraseProtected(keys)
55
43
}
56
44
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 (
64
46
password : String ,
65
47
identities : List <PGPIdentifier >,
66
48
message : ByteArrayInputStream ,
67
49
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
+ }
73
56
74
- private suspend fun encryptPgp (
57
+ suspend fun encrypt (
75
58
identities : List <PGPIdentifier >,
76
59
content : ByteArrayInputStream ,
77
60
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
+ }
86
70
}
0 commit comments