From cef5e06f0bad2e627c9cd102f6e8f511b1ba68b5 Mon Sep 17 00:00:00 2001 From: sergeych Date: Mon, 25 Sep 2023 14:14:32 +0100 Subject: [PATCH] support for extra reasons of registration failure --- build.gradle.kts | 12 ++++++------ .../kotlin/net.sergeych.superlogin/api.kt | 14 ++++++++++++-- .../net.sergeych.superlogin/client/Registration.kt | 7 ++++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d8bf19a..0157452 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ val logback_version="1.2.10" group = "net.sergeych" -version = "0.2.4" +version = "0.2.6-SNAPSHOT" repositories { mavenCentral() @@ -24,9 +24,9 @@ repositories { kotlin { jvm { - compilations.all { - kotlinOptions.jvmTarget = "1.8" - } +// compilations.all { +// kotlinOptions.jvmTarget = "1.8" +// } withJava() testRuns["test"].executionTask.configure { useJUnitPlatform() @@ -51,8 +51,8 @@ kotlin { val commonMain by getting { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3") - api("net.sergeych:unikrypto:1.2.2-SNAPSHOT") - api("net.sergeych:parsec3:0.4.5") +// api("net.sergeych:unikrypto:1.2.2-SNAPSHOT") + api("net.sergeych:parsec3:0.4.6") api("net.sergeych:unikrypto:1.2.5") } } diff --git a/src/commonMain/kotlin/net.sergeych.superlogin/api.kt b/src/commonMain/kotlin/net.sergeych.superlogin/api.kt index 8b6d3c4..a98050f 100644 --- a/src/commonMain/kotlin/net.sergeych.superlogin/api.kt +++ b/src/commonMain/kotlin/net.sergeych.superlogin/api.kt @@ -19,14 +19,19 @@ data class RegistrationArgs( val packedACO: ByteArray, val extraData: ByteArray? = null ) { + @Suppress("unused") + inline fun toSuccess(loginToken: ByteArray, extraData: T): AuthenticationResult.Success { return AuthenticationResult.Success( loginName, loginToken, BossEncoder.encode(extraData) ) } - inline fun decodeOrNull(): T? = extraData?.let { it.decodeBoss() } - inline fun decodeOrThrow(): T = extraData?.let { it.decodeBoss() } + @Suppress("unused") + inline fun decodeOrNull(): T? = extraData?.decodeBoss() + + @Suppress("unused") + inline fun decodeOrThrow(): T = extraData?.decodeBoss() ?: throw IllegalArgumentException("missing require extra data of type ${T::class.simpleName}") } @@ -44,6 +49,11 @@ sealed class AuthenticationResult { @SerialName("LoginUnavailable") object LoginUnavailable: AuthenticationResult() + @Serializable + @SerialName("OtherError") + class OtherError(val reason: String,val packedData: ByteArray?=null): AuthenticationResult() + + @Serializable @SerialName("LoginIdUnavailable") object LoginIdUnavailable: AuthenticationResult() diff --git a/src/commonMain/kotlin/net.sergeych.superlogin/client/Registration.kt b/src/commonMain/kotlin/net.sergeych.superlogin/client/Registration.kt index 452f865..984c1f8 100644 --- a/src/commonMain/kotlin/net.sergeych.superlogin/client/Registration.kt +++ b/src/commonMain/kotlin/net.sergeych.superlogin/client/Registration.kt @@ -34,6 +34,7 @@ class Registration( val pbkdfRounds: Int = 15000, ) : LogTag("SLREG") { + @Suppress("unused") sealed class Result { /** * Login is already in use or is somehow else invalid @@ -53,6 +54,8 @@ class Registration( val encodedData: ByteArray?) : Result() { inline fun data() = encodedData?.let { BossDecoder.decodeFrom(it)} } + + class OtherError(val code: String,val packedData: ByteArray?=null): Result() } private var lastPasswordHash: ByteArray? = null @@ -90,7 +93,7 @@ class Registration( val nonce = adapter.invokeCommand(api.slGetNonce) val loginPrivateKey = deferredLoginKey.await() val spl = SuperloginRestoreAccessPayload(login, loginPrivateKey, dataKey) - repeat(10) { + repeat(3) { val (restoreKey, restoreData) = AccessControlObject.pack(passwordKeys!!.loginAccessKey, spl) try { val packedArgs = SignedRecord.pack( @@ -122,6 +125,8 @@ class Registration( AuthenticationResult.LoginUnavailable -> return Result.InvalidLogin + is AuthenticationResult.OtherError -> return Result.OtherError(result.reason, result.packedData) + is AuthenticationResult.Success -> { return Result.Success( restoreKey.secret,