From 6d73b63435a2760ec9026090ecfea4846157b6ab Mon Sep 17 00:00:00 2001 From: Newton Cesar Date: Sat, 8 Oct 2022 12:03:29 -0300 Subject: Fix detekt warnings in format-common (#2167) * fix warning ktlint to format-common folder * update to code review * adjusted spotless --- .../app/passwordstore/data/passfile/PasswordEntry.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'format-common/src/main/kotlin/app/passwordstore/data') 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): Pair> { 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 } } -- cgit v1.2.3