Compare commits

...

1 commit

Author SHA1 Message Date
6986ab5a1c
feat: improve lpa parsing compatibility 2025-03-07 15:46:42 +08:00

View file

@ -8,13 +8,12 @@ data class ActivationCode(
) { ) {
companion object { companion object {
fun fromString(input: String): ActivationCode { fun fromString(input: String): ActivationCode {
val components = input.removePrefix("LPA:").split('$') check(input.startsWith("LPA:", ignoreCase = true)) { "Invalid activation code format" }
.map(String::trim).map { it.ifBlank { null } } val components = input.drop(4).split('$').map { it.trim().ifEmpty { null } }
if (components.size < 2 || components[0] != "1" || components[1] == null) { check(components.size >= 2) { "Invalid activation code format" }
throw IllegalStateException("Invalid activation code format") check(components[0] == "1") { "Invalid activation code version" }
}
return ActivationCode( return ActivationCode(
components[1]!!, checkNotNull(components[1]) { "Invalid SM-DP+ address" },
components.getOrNull(2), components.getOrNull(2),
components.getOrNull(3), components.getOrNull(3),
components.getOrNull(4) == "1", components.getOrNull(4) == "1",