fix: improve lpa string parsing #181

Merged
PeterCxy merged 3 commits from septs/OpenEUICC:improve-lpa-string-parsing into master 2025-04-01 03:19:22 +02:00

View file

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