Compare commits
1 commit
6986ab5a1c
...
a9479d9106
Author | SHA1 | Date | |
---|---|---|---|
a9479d9106 |
1 changed files with 6 additions and 7 deletions
|
@ -7,14 +7,13 @@ data class ActivationCode(
|
||||||
val confirmationCodeRequired: Boolean = false,
|
val confirmationCodeRequired: Boolean = false,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun fromString(input: String): ActivationCode {
|
fun fromString(token: String): ActivationCode {
|
||||||
val components = input.removePrefix("LPA:").split('$')
|
val input = if (token.startsWith("LPA:", true)) token.drop(4) else token
|
||||||
.map(String::trim).map { it.ifBlank { null } }
|
val components = input.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",
|
||||||
|
|
Loading…
Add table
Reference in a new issue