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 --- app/build.gradle.kts | 2 +- .../app/passwordstore/util/totp/UriTotpFinder.kt | 53 ---------------------- 2 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 app/src/main/java/app/passwordstore/util/totp/UriTotpFinder.kt (limited to 'app') diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 32291d33..54bf2af7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -56,7 +56,7 @@ dependencies { implementation(projects.autofillParser) implementation(projects.coroutineUtils) implementation(projects.cryptoPgpainless) - implementation(projects.formatCommon) + implementation(projects.formatCommonImpl) implementation(projects.passgen.diceware) implementation(projects.passgen.random) implementation(projects.uiCompose) diff --git a/app/src/main/java/app/passwordstore/util/totp/UriTotpFinder.kt b/app/src/main/java/app/passwordstore/util/totp/UriTotpFinder.kt deleted file mode 100644 index 30447690..00000000 --- a/app/src/main/java/app/passwordstore/util/totp/UriTotpFinder.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -package app.passwordstore.util.totp - -import android.net.Uri -import javax.inject.Inject - -/** [Uri] backed TOTP URL parser. */ -class UriTotpFinder @Inject constructor() : TotpFinder { - - 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() ?: 30 - } - - 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 - } -} -- cgit v1.2.3