aboutsummaryrefslogtreecommitdiffstats
path: root/format-common/src/main/kotlin/app/passwordstore/util
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-10-21 21:36:27 +0530
committerGitHub <noreply@github.com>2022-10-21 21:36:27 +0530
commitcdf0f30c61e55fc94524c2fd3f07ffda367555f1 (patch)
treef1d4a029c78105560947def5a3d5c423f4b096d0 /format-common/src/main/kotlin/app/passwordstore/util
parentdf764932f7fdddea9cea5937c6053a95797d35df (diff)
downloadHardenedPass-cdf0f30c61e55fc94524c2fd3f07ffda367555f1.tar.gz
HardenedPass-cdf0f30c61e55fc94524c2fd3f07ffda367555f1.zip
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
Diffstat (limited to 'format-common/src/main/kotlin/app/passwordstore/util')
-rw-r--r--format-common/src/main/kotlin/app/passwordstore/util/totp/Otp.kt7
1 files changed, 4 insertions, 3 deletions
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<String, Throwable> = runCatching {
val algo = "Hmac${algorithm.uppercase(Locale.ROOT)}"
val decodedSecret = BASE_32.decode(secret)
val secretKey = SecretKeySpec(decodedSecret, algo)