diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-01-18 17:40:16 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-18 17:40:16 +0530 |
commit | 5509558eedbcd90f130b32d4e6c41632da291b15 (patch) | |
tree | 7b6839928889698ebe0da48a83b2e1532ed6d094 /app/src | |
parent | 3ead6596ba9c2b65434f6cd948bf6ebf41a230eb (diff) |
Parameterize key and key identifier types for KeyManager (#1669)
Diffstat (limited to 'app/src')
3 files changed, 6 insertions, 18 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/crypto/CryptoHandlerModule.kt b/app/src/main/java/dev/msfjarvis/aps/injection/crypto/CryptoHandlerModule.kt index 63a860d1..ef6a11ce 100644 --- a/app/src/main/java/dev/msfjarvis/aps/injection/crypto/CryptoHandlerModule.kt +++ b/app/src/main/java/dev/msfjarvis/aps/injection/crypto/CryptoHandlerModule.kt @@ -9,23 +9,10 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import dagger.multibindings.IntoSet -import dev.msfjarvis.aps.crypto.CryptoHandler import dev.msfjarvis.aps.crypto.PGPainlessCryptoHandler -/** - * This module adds all [CryptoHandler] implementations into a Set which makes it easier to build - * generic UIs which are not tied to a specific implementation because of injection. - */ @Module @InstallIn(SingletonComponent::class) object CryptoHandlerModule { - @Provides - @IntoSet - fun providePgpCryptoHandler(): CryptoHandler { - return PGPainlessCryptoHandler() - } + @Provides fun providePgpCryptoHandler() = PGPainlessCryptoHandler() } - -/** Typealias for a [Set] of [CryptoHandler] instances injected by Dagger. */ -typealias CryptoSet = Set<@JvmSuppressWildcards CryptoHandler> diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/crypto/KeyManagerModule.kt b/app/src/main/java/dev/msfjarvis/aps/injection/crypto/KeyManagerModule.kt index 0bc1c43d..a1119a1c 100644 --- a/app/src/main/java/dev/msfjarvis/aps/injection/crypto/KeyManagerModule.kt +++ b/app/src/main/java/dev/msfjarvis/aps/injection/crypto/KeyManagerModule.kt @@ -12,8 +12,8 @@ import dagger.hilt.InstallIn import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import dev.msfjarvis.aps.crypto.PGPKeyManager +import dev.msfjarvis.aps.util.coroutines.DispatcherProvider import javax.inject.Qualifier -import kotlinx.coroutines.Dispatchers @Module @InstallIn(SingletonComponent::class) @@ -21,10 +21,11 @@ object KeyManagerModule { @Provides fun providePGPKeyManager( @PGPKeyDir keyDir: String, + dispatcherProvider: DispatcherProvider, ): PGPKeyManager { return PGPKeyManager( keyDir, - Dispatchers.IO, + dispatcherProvider.io(), ) } diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/pgp/PGPKeyImportActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/pgp/PGPKeyImportActivity.kt index 3cd6930c..b97de5e0 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/pgp/PGPKeyImportActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/pgp/PGPKeyImportActivity.kt @@ -14,8 +14,8 @@ import com.github.michaelbull.result.runCatching import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint import dev.msfjarvis.aps.R -import dev.msfjarvis.aps.crypto.Key import dev.msfjarvis.aps.crypto.KeyUtils.tryGetId +import dev.msfjarvis.aps.crypto.PGPKey import dev.msfjarvis.aps.crypto.PGPKeyManager import javax.inject.Inject import kotlinx.coroutines.runBlocking @@ -35,7 +35,7 @@ class PGPKeyImportActivity : AppCompatActivity() { contentResolver.openInputStream(uri) ?: throw IllegalStateException("Failed to open selected file") val bytes = keyInputStream.readBytes() - val (key, error) = runBlocking { keyManager.addKey(Key(bytes)) } + val (key, error) = runBlocking { keyManager.addKey(PGPKey(bytes)) } if (error != null) throw error key } |