diff options
-rw-r--r-- | app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt | 9 | ||||
-rw-r--r-- | crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt b/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt index 233dedef..f3a82f39 100644 --- a/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt +++ b/app/src/main/java/app/passwordstore/data/crypto/CryptoRepository.kt @@ -5,12 +5,15 @@ package app.passwordstore.data.crypto +import android.content.SharedPreferences import app.passwordstore.crypto.GpgIdentifier import app.passwordstore.crypto.PGPDecryptOptions import app.passwordstore.crypto.PGPEncryptOptions import app.passwordstore.crypto.PGPKeyManager import app.passwordstore.crypto.PGPainlessCryptoHandler import app.passwordstore.crypto.errors.CryptoHandlerException +import app.passwordstore.injection.prefs.SettingsPreferences +import app.passwordstore.util.settings.PreferenceKeys import com.github.michaelbull.result.Result import com.github.michaelbull.result.getAll import com.github.michaelbull.result.unwrap @@ -25,6 +28,7 @@ class CryptoRepository constructor( private val pgpKeyManager: PGPKeyManager, private val pgpCryptoHandler: PGPainlessCryptoHandler, + @SettingsPreferences private val settings: SharedPreferences, ) { suspend fun decrypt( @@ -54,7 +58,10 @@ constructor( content: ByteArrayInputStream, out: ByteArrayOutputStream, ): Result<Unit, CryptoHandlerException> { - val encryptionOptions = PGPEncryptOptions.Builder().build() + val encryptionOptions = + PGPEncryptOptions.Builder() + .withAsciiArmor(settings.getBoolean(PreferenceKeys.ASCII_ARMOR, false)) + .build() val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.getAll() return pgpCryptoHandler.encrypt( keys, diff --git a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt index 91c17004..e1084dec 100644 --- a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt +++ b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt @@ -83,7 +83,9 @@ public class PGPainlessCryptoHandler @Inject constructor() : require(publicKeyRings.isNotEmpty()) { "No public keys to encrypt message to" } val publicKeyRingCollection = PGPPublicKeyRingCollection(publicKeyRings) val encryptionOptions = EncryptionOptions().addRecipients(publicKeyRingCollection) - val producerOptions = ProducerOptions.encrypt(encryptionOptions).setAsciiArmor(false) + val producerOptions = + ProducerOptions.encrypt(encryptionOptions) + .setAsciiArmor(options.isOptionEnabled(PGPEncryptOptions.ASCII_ARMOR)) val encryptor = PGPainless.encryptAndOrSign().onOutputStream(outputStream).withOptions(producerOptions) plaintextStream.copyTo(encryptor) |