Revert "refactor(app): inline pointless methods in CryptoRepository
"
This reverts commit b05a6d411b
.
This commit is contained in:
parent
a2ede93cf5
commit
cb22561878
1 changed files with 33 additions and 17 deletions
|
@ -11,9 +11,11 @@ import app.passwordstore.crypto.PGPEncryptOptions
|
||||||
import app.passwordstore.crypto.PGPIdentifier
|
import app.passwordstore.crypto.PGPIdentifier
|
||||||
import app.passwordstore.crypto.PGPKeyManager
|
import app.passwordstore.crypto.PGPKeyManager
|
||||||
import app.passwordstore.crypto.PGPainlessCryptoHandler
|
import app.passwordstore.crypto.PGPainlessCryptoHandler
|
||||||
|
import app.passwordstore.crypto.errors.CryptoHandlerException
|
||||||
import app.passwordstore.injection.prefs.SettingsPreferences
|
import app.passwordstore.injection.prefs.SettingsPreferences
|
||||||
import app.passwordstore.util.coroutines.DispatcherProvider
|
import app.passwordstore.util.coroutines.DispatcherProvider
|
||||||
import app.passwordstore.util.settings.PreferenceKeys
|
import app.passwordstore.util.settings.PreferenceKeys
|
||||||
|
import com.github.michaelbull.result.Result
|
||||||
import com.github.michaelbull.result.filterValues
|
import com.github.michaelbull.result.filterValues
|
||||||
import com.github.michaelbull.result.map
|
import com.github.michaelbull.result.map
|
||||||
import com.github.michaelbull.result.mapBoth
|
import com.github.michaelbull.result.mapBoth
|
||||||
|
@ -37,11 +39,6 @@ constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun isPasswordProtected(identifiers: List<PGPIdentifier>): Boolean {
|
|
||||||
val keys = identifiers.map { pgpKeyManager.getKeyById(it) }.filterValues()
|
|
||||||
return pgpCryptoHandler.isPassphraseProtected(keys)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun decrypt(
|
suspend fun decrypt(
|
||||||
password: String,
|
password: String,
|
||||||
identities: List<PGPIdentifier>,
|
identities: List<PGPIdentifier>,
|
||||||
|
@ -49,22 +46,41 @@ constructor(
|
||||||
out: ByteArrayOutputStream,
|
out: ByteArrayOutputStream,
|
||||||
) =
|
) =
|
||||||
withContext(dispatcherProvider.io()) {
|
withContext(dispatcherProvider.io()) {
|
||||||
val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
|
decryptPgp(password, identities, message, out).map { out }
|
||||||
val decryptionOptions = PGPDecryptOptions.Builder().build()
|
}
|
||||||
pgpCryptoHandler.decrypt(keys, password, message, out, decryptionOptions).map { out }
|
|
||||||
|
suspend fun isPasswordProtected(identifiers: List<PGPIdentifier>): Boolean {
|
||||||
|
val keys = identifiers.map { pgpKeyManager.getKeyById(it) }.filterValues()
|
||||||
|
return pgpCryptoHandler.isPassphraseProtected(keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun encrypt(
|
suspend fun encrypt(
|
||||||
identities: List<PGPIdentifier>,
|
identities: List<PGPIdentifier>,
|
||||||
content: ByteArrayInputStream,
|
content: ByteArrayInputStream,
|
||||||
out: ByteArrayOutputStream,
|
out: ByteArrayOutputStream,
|
||||||
) =
|
) = withContext(dispatcherProvider.io()) { encryptPgp(identities, content, out).map { out } }
|
||||||
withContext(dispatcherProvider.io()) {
|
|
||||||
|
private suspend fun decryptPgp(
|
||||||
|
password: String,
|
||||||
|
identities: List<PGPIdentifier>,
|
||||||
|
message: ByteArrayInputStream,
|
||||||
|
out: ByteArrayOutputStream,
|
||||||
|
): Result<Unit, CryptoHandlerException> {
|
||||||
|
val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
|
||||||
|
val decryptionOptions = PGPDecryptOptions.Builder().build()
|
||||||
|
return pgpCryptoHandler.decrypt(keys, password, message, out, decryptionOptions)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun encryptPgp(
|
||||||
|
identities: List<PGPIdentifier>,
|
||||||
|
content: ByteArrayInputStream,
|
||||||
|
out: ByteArrayOutputStream,
|
||||||
|
): Result<Unit, CryptoHandlerException> {
|
||||||
val encryptionOptions =
|
val encryptionOptions =
|
||||||
PGPEncryptOptions.Builder()
|
PGPEncryptOptions.Builder()
|
||||||
.withAsciiArmor(settings.getBoolean(PreferenceKeys.ASCII_ARMOR, false))
|
.withAsciiArmor(settings.getBoolean(PreferenceKeys.ASCII_ARMOR, false))
|
||||||
.build()
|
.build()
|
||||||
val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
|
val keys = identities.map { id -> pgpKeyManager.getKeyById(id) }.filterValues()
|
||||||
pgpCryptoHandler.encrypt(keys, content, out, encryptionOptions).map { out }
|
return pgpCryptoHandler.encrypt(keys, content, out, encryptionOptions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue