aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/dev/msfjarvis
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-12-21 00:15:13 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2021-12-21 13:01:41 +0530
commit0e8f8994344c38fcf09e5910d8a599530fb58027 (patch)
tree9000b8753983744eb1ea53e8f1ddf831727da918 /app/src/main/java/dev/msfjarvis
parent5bcbf8da0859bce94ed41b757fa3f44e7a15da8b (diff)
app: add diceware injection module
Diffstat (limited to 'app/src/main/java/dev/msfjarvis')
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/injection/pwgen/DicewareModule.kt55
1 files changed, 55 insertions, 0 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/injection/pwgen/DicewareModule.kt b/app/src/main/java/dev/msfjarvis/aps/injection/pwgen/DicewareModule.kt
new file mode 100644
index 00000000..8aed12de
--- /dev/null
+++ b/app/src/main/java/dev/msfjarvis/aps/injection/pwgen/DicewareModule.kt
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+package dev.msfjarvis.aps.injection.pwgen
+
+import android.content.Context
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.android.components.FragmentComponent
+import dagger.hilt.android.qualifiers.ApplicationContext
+import dev.msfjarvis.aps.passgen.diceware.DicewarePassphraseGenerator
+import dev.msfjarvis.aps.passgen.diceware.Die
+import dev.msfjarvis.aps.passgen.diceware.RandomIntGenerator
+import java.io.InputStream
+import java.security.SecureRandom
+import javax.inject.Qualifier
+
+@Module
+@InstallIn(FragmentComponent::class)
+object DicewareModule {
+
+ @Provides
+ fun provideDicewareGenerator(
+ die: Die,
+ @WordlistQualifier wordList: InputStream,
+ ): DicewarePassphraseGenerator {
+ return DicewarePassphraseGenerator(die, wordList)
+ }
+
+ @Provides
+ fun provideDie(
+ intGenerator: RandomIntGenerator,
+ ): Die {
+ return Die(6, intGenerator)
+ }
+
+ @Provides
+ fun provideRandomIntGenerator(): RandomIntGenerator {
+ return RandomIntGenerator { range ->
+ SecureRandom().nextInt(range.last).coerceAtLeast(range.first)
+ }
+ }
+
+ @[Provides WordlistQualifier]
+ fun provideDefaultWordList(@ApplicationContext context: Context): InputStream {
+ return context.resources.openRawResource(
+ dev.msfjarvis.aps.passgen.diceware.R.raw.diceware_wordlist
+ )
+ }
+}
+
+@Qualifier annotation class WordlistQualifier