From cdf0f30c61e55fc94524c2fd3f07ffda367555f1 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 21 Oct 2022 21:36:27 +0530 Subject: Refactor `format-common` module (#2196) * fix: touch up `PasswordEntryTest` KDoc * feat: add format-common-impl module * refactor: switch app to format-common-impl * refactor: move `format-common` tests to `format-common-impl` * feat: add a test for Steam OTP --- format-common/src/main/kotlin/app/passwordstore/util/totp/Otp.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'format-common/src/main/kotlin/app/passwordstore/util') diff --git a/format-common/src/main/kotlin/app/passwordstore/util/totp/Otp.kt b/format-common/src/main/kotlin/app/passwordstore/util/totp/Otp.kt index 5abc0337..10e771fe 100644 --- a/format-common/src/main/kotlin/app/passwordstore/util/totp/Otp.kt +++ b/format-common/src/main/kotlin/app/passwordstore/util/totp/Otp.kt @@ -6,6 +6,7 @@ package app.passwordstore.util.totp import com.github.michaelbull.result.Err +import com.github.michaelbull.result.Result import com.github.michaelbull.result.runCatching import java.nio.ByteBuffer import java.util.Locale @@ -14,7 +15,7 @@ import javax.crypto.spec.SecretKeySpec import kotlin.experimental.and import org.apache.commons.codec.binary.Base32 -internal object Otp { +public object Otp { private val BASE_32 = Base32() private val STEAM_ALPHABET = "23456789BCDFGHJKMNPQRTVWXY".toCharArray() @@ -26,13 +27,13 @@ internal object Otp { private const val ALPHABET_LENGTH = 26 private const val MOST_SIGNIFICANT_BYTE = 0x7f - fun calculateCode( + public fun calculateCode( secret: String, counter: Long, algorithm: String, digits: String, issuer: String?, - ) = runCatching { + ): Result = runCatching { val algo = "Hmac${algorithm.uppercase(Locale.ROOT)}" val decodedSecret = BASE_32.decode(secret) val secretKey = SecretKeySpec(decodedSecret, algo) -- cgit v1.2.3