@@ -17,6 +17,7 @@ import androidx.lifecycle.lifecycleScope
17
17
import app.passwordstore.Application.Companion.screenWasOff
18
18
import app.passwordstore.R
19
19
import app.passwordstore.crypto.PGPIdentifier
20
+ import app.passwordstore.crypto.errors.CryptoHandlerException
20
21
import app.passwordstore.data.crypto.PGPPassphraseCache
21
22
import app.passwordstore.data.passfile.PasswordEntry
22
23
import app.passwordstore.data.repo.PasswordRepository
@@ -33,11 +34,14 @@ import app.passwordstore.util.features.Features
33
34
import app.passwordstore.util.settings.PreferenceKeys
34
35
import com.github.androidpasswordstore.autofillparser.AutofillAction
35
36
import com.github.androidpasswordstore.autofillparser.Credentials
37
+ import com.github.michaelbull.result.Result
36
38
import com.github.michaelbull.result.getOrElse
39
+ import com.github.michaelbull.result.map
37
40
import com.github.michaelbull.result.onFailure
38
41
import com.github.michaelbull.result.onSuccess
39
42
import com.github.michaelbull.result.runCatching
40
43
import dagger.hilt.android.AndroidEntryPoint
44
+ import java.io.ByteArrayInputStream
41
45
import java.io.ByteArrayOutputStream
42
46
import java.io.File
43
47
import javax.inject.Inject
@@ -209,20 +213,16 @@ class AutofillDecryptActivity : BasePGPActivity() {
209
213
return null
210
214
}
211
215
.onSuccess { encryptedInput ->
212
- runCatching {
213
- withContext(dispatcherProvider.io()) {
214
- val outputStream = ByteArrayOutputStream ()
215
- repository.decrypt(password, identifiers, encryptedInput, outputStream)
216
- outputStream
217
- }
218
- }
216
+ decryptPGPStream(encryptedInput, password, identifiers)
219
217
.onFailure { e ->
220
218
logcat(ERROR ) { e.asLog(" Decryption failed" ) }
221
219
return null
222
220
}
223
221
.onSuccess { result ->
224
222
return runCatching {
225
- passphraseCache.cachePassphrase(this , identifiers.first(), password)
223
+ if (features.isEnabled(EnablePGPPassphraseCache )) {
224
+ passphraseCache.cachePassphrase(this , identifiers.first(), password)
225
+ }
226
226
val entry = passwordEntryFactory.create(result.toByteArray())
227
227
AutofillPreferences .credentialsFromStoreEntry(this , file, entry, directoryStructure)
228
228
}
@@ -235,6 +235,17 @@ class AutofillDecryptActivity : BasePGPActivity() {
235
235
return null
236
236
}
237
237
238
+ private suspend fun decryptPGPStream (
239
+ message : ByteArrayInputStream ,
240
+ passphrase : String ,
241
+ gpgIdentifiers : List <PGPIdentifier >,
242
+ ): Result <ByteArrayOutputStream , CryptoHandlerException > {
243
+ val outputStream = ByteArrayOutputStream ()
244
+ return repository.decrypt(passphrase, gpgIdentifiers, message, outputStream).map {
245
+ outputStream
246
+ }
247
+ }
248
+
238
249
companion object {
239
250
240
251
private const val EXTRA_FILE_PATH = " app.passwordstore.autofill.oreo.EXTRA_FILE_PATH"
0 commit comments