diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-12-19 16:47:17 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-12-19 16:47:17 +0530 |
commit | 8cfe6ec84c1bd8119fd59fbb76d729da284ced27 (patch) | |
tree | 7035f03675f8924bfc3870b68b6345faf020aaac /format-common-impl/src/main | |
parent | 39a0284cd55298eb4930db681e813260aea58867 (diff) |
refactor: merge format-common-impl into format-common
Also converts the format-common module into an Android library since
UriTotpFinder requires the Android SDK.
Diffstat (limited to 'format-common-impl/src/main')
-rw-r--r-- | format-common-impl/src/main/kotlin/app/passwordstore/util/totp/UriTotpFinder.kt | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/format-common-impl/src/main/kotlin/app/passwordstore/util/totp/UriTotpFinder.kt b/format-common-impl/src/main/kotlin/app/passwordstore/util/totp/UriTotpFinder.kt deleted file mode 100644 index 741a21a7..00000000 --- a/format-common-impl/src/main/kotlin/app/passwordstore/util/totp/UriTotpFinder.kt +++ /dev/null @@ -1,52 +0,0 @@ -package app.passwordstore.util.totp - -import android.net.Uri -import javax.inject.Inject - -/** [Uri] backed TOTP URL parser. */ -public class UriTotpFinder @Inject constructor() : TotpFinder { - - private companion object { - private const val DEFAULT_TOTP_PERIOD = 30L - } - - override fun findSecret(content: String): String? { - content.split("\n".toRegex()).forEach { line -> - if (line.startsWith(TotpFinder.TOTP_FIELDS[0])) { - return Uri.parse(line).getQueryParameter("secret") - } - if (line.startsWith(TotpFinder.TOTP_FIELDS[1], ignoreCase = true)) { - return line.split(": *".toRegex(), 2).toTypedArray()[1] - } - } - return null - } - - override fun findDigits(content: String): String { - return getQueryParameter(content, "digits") ?: "6" - } - - override fun findPeriod(content: String): Long { - return getQueryParameter(content, "period")?.toLongOrNull() ?: DEFAULT_TOTP_PERIOD - } - - override fun findAlgorithm(content: String): String { - return getQueryParameter(content, "algorithm") ?: "sha1" - } - - override fun findIssuer(content: String): String? { - return getQueryParameter(content, "issuer") ?: Uri.parse(content).authority - } - - private fun getQueryParameter(content: String, parameterName: String): String? { - content.split("\n".toRegex()).forEach { line -> - val uri = Uri.parse(line) - if ( - line.startsWith(TotpFinder.TOTP_FIELDS[0]) && uri.getQueryParameter(parameterName) != null - ) { - return uri.getQueryParameter(parameterName) - } - } - return null - } -} |