diff options
Diffstat (limited to 'format-common/src/main/kotlin/app/passwordstore/data')
| -rw-r--r-- | format-common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt | 14 |
1 files changed, 11 insertions, 3 deletions
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 9543eb8c..38aa4a20 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 @@ -62,7 +62,7 @@ constructor( do { val otp = calculateTotp() emit(otp) - delay(1000L) + delay(ONE_SECOND.seconds) } while (coroutineContext.isActive) } else { awaitCancellation() @@ -90,6 +90,7 @@ constructor( return totpSecret != null } + @Suppress("ReturnCount") private fun findAndStripPassword(passContent: List<String>): Pair<String?, List<String>> { if (TotpFinder.TOTP_FIELDS.any { passContent[0].startsWith(it) }) return Pair(null, passContent) for (line in passContent) { @@ -180,8 +181,14 @@ constructor( val totpAlgorithm = totpFinder.findAlgorithm(content) val issuer = totpFinder.findIssuer(content) val millis = clock.millis() - val remainingTime = (totpPeriod - ((millis / 1000) % totpPeriod)).seconds - Otp.calculateCode(totpSecret!!, millis / (1000 * totpPeriod), totpAlgorithm, digits, issuer) + val remainingTime = (totpPeriod - ((millis / ONE_SECOND) % totpPeriod)).seconds + Otp.calculateCode( + totpSecret!!, + millis / (ONE_SECOND * totpPeriod), + totpAlgorithm, + digits, + issuer + ) .mapBoth( { code -> return Totp(code, remainingTime) @@ -217,5 +224,6 @@ constructor( "secret:", "pass:", ) + private const val ONE_SECOND = 1000 } } |
