@@ -17,6 +17,7 @@ import androidx.lifecycle.lifecycleScope
1717import app.passwordstore.Application.Companion.screenWasOff
1818import app.passwordstore.R
1919import app.passwordstore.crypto.PGPIdentifier
20+ import app.passwordstore.crypto.errors.CryptoHandlerException
2021import app.passwordstore.data.crypto.PGPPassphraseCache
2122import app.passwordstore.data.passfile.PasswordEntry
2223import app.passwordstore.data.repo.PasswordRepository
@@ -33,11 +34,14 @@ import app.passwordstore.util.features.Features
3334import app.passwordstore.util.settings.PreferenceKeys
3435import com.github.androidpasswordstore.autofillparser.AutofillAction
3536import com.github.androidpasswordstore.autofillparser.Credentials
37+ import com.github.michaelbull.result.Result
3638import com.github.michaelbull.result.getOrElse
39+ import com.github.michaelbull.result.map
3740import com.github.michaelbull.result.onFailure
3841import com.github.michaelbull.result.onSuccess
3942import com.github.michaelbull.result.runCatching
4043import dagger.hilt.android.AndroidEntryPoint
44+ import java.io.ByteArrayInputStream
4145import java.io.ByteArrayOutputStream
4246import java.io.File
4347import javax.inject.Inject
@@ -209,20 +213,16 @@ class AutofillDecryptActivity : BasePGPActivity() {
209213 return null
210214 }
211215 .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)
219217 .onFailure { e ->
220218 logcat(ERROR ) { e.asLog(" Decryption failed" ) }
221219 return null
222220 }
223221 .onSuccess { result ->
224222 return runCatching {
225- passphraseCache.cachePassphrase(this , identifiers.first(), password)
223+ if (features.isEnabled(EnablePGPPassphraseCache )) {
224+ passphraseCache.cachePassphrase(this , identifiers.first(), password)
225+ }
226226 val entry = passwordEntryFactory.create(result.toByteArray())
227227 AutofillPreferences .credentialsFromStoreEntry(this , file, entry, directoryStructure)
228228 }
@@ -235,6 +235,17 @@ class AutofillDecryptActivity : BasePGPActivity() {
235235 return null
236236 }
237237
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+
238249 companion object {
239250
240251 private const val EXTRA_FILE_PATH = " app.passwordstore.autofill.oreo.EXTRA_FILE_PATH"
0 commit comments