Compare commits

...

1 commit

Author SHA1 Message Date
bb5417d37f
chore: improve lpa string parsing 2025-03-16 16:15:16 +08:00
2 changed files with 9 additions and 9 deletions

View file

@ -126,7 +126,7 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard
state.matchingId = parsed.matchingId
state.confirmationCodeRequired = parsed.confirmationCodeRequired
gotoNextFragment(DownloadWizardDetailsFragment())
} catch (e: IllegalArgumentException) {
} catch (e: IllegalStateException) {
AlertDialog.Builder(requireContext()).apply {
setTitle(R.string.profile_download_incorrect_lpa_string)
setMessage(R.string.profile_download_incorrect_lpa_string_message)

View file

@ -8,15 +8,15 @@ data class LPAString(
) {
companion object {
fun parse(input: String): LPAString {
val components = input.removePrefix("LPA:").split('$')
if (components.size < 2 || components[0] != "1") {
throw IllegalArgumentException("Invalid activation code format")
}
var token = input
if (token.startsWith("LPA:", ignoreCase = true)) token = token.drop(4)
val components = token.split('$').map { it.trim().ifBlank { null } }
check(components.getOrNull(0) == "1") { "Invalid AC_Format" }
return LPAString(
address = components[1].trim(),
matchingId = components.getOrNull(2)?.trim()?.ifBlank { null },
oid = components.getOrNull(3)?.trim()?.ifBlank { null },
confirmationCodeRequired = components.getOrNull(4)?.trim() == "1"
checkNotNull(components.getOrNull(1)) { "SM-DP+ is required" },
components.getOrNull(2),
components.getOrNull(3),
components.getOrNull(4) == "1"
)
}
}