aboutsummaryrefslogtreecommitdiff
path: root/format-common/src/main/kotlin
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
parentdf764932f7fdddea9cea5937c6053a95797d35df (diff)
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')
-rw-r--r--format-common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt9
-rw-r--r--format-common/src/main/kotlin/app/passwordstore/util/totp/Otp.kt7
2 files changed, 10 insertions, 6 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 38aa4a20..d48c2ca3 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
@@ -5,6 +5,7 @@
package app.passwordstore.data.passfile
+import androidx.annotation.VisibleForTesting
import app.passwordstore.util.time.UserClock
import app.passwordstore.util.totp.Otp
import app.passwordstore.util.totp.TotpFinder
@@ -202,10 +203,11 @@ constructor(
public fun create(bytes: ByteArray): PasswordEntry
}
- internal companion object {
+ public companion object {
private const val EXTRA_CONTENT = "Extra Content"
- internal val USERNAME_FIELDS =
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ public val USERNAME_FIELDS: Array<String> =
arrayOf(
"login:",
"username:",
@@ -218,7 +220,8 @@ constructor(
"id:",
"identity:",
)
- internal val PASSWORD_FIELDS =
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ public val PASSWORD_FIELDS: Array<String> =
arrayOf(
"password:",
"secret:",
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)