refactor(format-common): add a getter to PasswordEntry for current OTP value

This commit is contained in:
Harsh Shandilya 2022-10-29 05:34:09 +05:30
parent e8d9a77539
commit 505c2fa705
No known key found for this signature in database
2 changed files with 5 additions and 3 deletions

View file

@ -15,8 +15,6 @@ import app.passwordstore.util.settings.PreferenceKeys
import com.github.androidpasswordstore.autofillparser.Credentials import com.github.androidpasswordstore.autofillparser.Credentials
import java.io.File import java.io.File
import java.nio.file.Paths import java.nio.file.Paths
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
enum class DirectoryStructure(val value: String) { enum class DirectoryStructure(val value: String) {
EncryptedUsername("encrypted_username"), EncryptedUsername("encrypted_username"),
@ -143,7 +141,7 @@ object AutofillPreferences {
// Always give priority to a username stored in the encrypted extras // Always give priority to a username stored in the encrypted extras
val username = val username =
entry.username ?: directoryStructure.getUsernameFor(file) ?: context.getDefaultUsername() 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) return Credentials(username, entry.password, totp)
} }
} }

View file

@ -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 * String representation of [extraContent] but with authentication related data such as TOTP URIs
* and usernames stripped. * and usernames stripped.