summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-10-29 05:34:09 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-10-29 05:34:09 +0530
commit505c2fa705fca1aaec7aae80c50a939bfd607716 (patch)
tree9877b7f00125ff8f5bf72cd649231c706ffd4ac4
parente8d9a7753917476ac578f9fb14d365c83699c89a (diff)
refactor(format-common): add a getter to `PasswordEntry` for current OTP value
-rw-r--r--app/src/main/java/app/passwordstore/util/autofill/AutofillPreferences.kt4
-rw-r--r--format-common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt4
2 files changed, 5 insertions, 3 deletions
diff --git a/app/src/main/java/app/passwordstore/util/autofill/AutofillPreferences.kt b/app/src/main/java/app/passwordstore/util/autofill/AutofillPreferences.kt
index ba3e5079..dc587cda 100644
--- a/app/src/main/java/app/passwordstore/util/autofill/AutofillPreferences.kt
+++ b/app/src/main/java/app/passwordstore/util/autofill/AutofillPreferences.kt
@@ -15,8 +15,6 @@ import app.passwordstore.util.settings.PreferenceKeys
import com.github.androidpasswordstore.autofillparser.Credentials
import java.io.File
import java.nio.file.Paths
-import kotlinx.coroutines.flow.first
-import kotlinx.coroutines.runBlocking
enum class DirectoryStructure(val value: String) {
EncryptedUsername("encrypted_username"),
@@ -143,7 +141,7 @@ object AutofillPreferences {
// Always give priority to a username stored in the encrypted extras
val username =
entry.username ?: directoryStructure.getUsernameFor(file) ?: context.getDefaultUsername()
- val totp = if (entry.hasTotp()) runBlocking { entry.totp.first().value } else null
+ val totp = if (entry.hasTotp()) entry.currentOtp else null
return Credentials(username, entry.password, totp)
}
}
diff --git a/format-common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt b/format-common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt
index d48c2ca3..cda8138e 100644
--- a/format-common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt
+++ b/format-common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt
@@ -70,6 +70,10 @@ constructor(
}
}
+ /** Obtain the [Totp.value] for this [PasswordEntry] at the current time. */
+ public val currentOtp: String
+ get() = calculateTotp().value
+
/**
* String representation of [extraContent] but with authentication related data such as TOTP URIs
* and usernames stripped.