Rename BotAuthorizationResult to BotAuthResult

This commit is contained in:
Him188 2023-03-02 13:12:40 +00:00
parent 9819381118
commit 9d61a675af
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
4 changed files with 32 additions and 32 deletions

View File

@ -52,7 +52,7 @@ public interface BotAuthorization {
public suspend fun authorize(
authComponent: BotAuthComponent,
bot: BotAuthInfo,
): BotAuthorizationResult
): BotAuthResult
/**
@ -84,7 +84,7 @@ public interface BotAuthorization {
override suspend fun authorize(
authComponent: MiraiInternalBotAuthComponent,
bot: BotAuthInfo
): BotAuthorizationResult {
): BotAuthResult {
return authComponent.authByPassword(passwordMd5)
}
@ -100,7 +100,7 @@ public interface BotAuthorization {
override suspend fun authorize(
authComponent: BotAuthComponent,
bot: BotAuthInfo
): BotAuthorizationResult {
): BotAuthResult {
return authComponent.authByQRCode()
}
@ -111,13 +111,13 @@ public interface BotAuthorization {
}
public operator fun invoke(
block: suspend (BotAuthComponent, BotAuthInfo) -> BotAuthorizationResult
block: suspend (BotAuthComponent, BotAuthInfo) -> BotAuthResult
): BotAuthorization {
return object : BotAuthorization {
override suspend fun authorize(
authComponent: BotAuthComponent,
bot: BotAuthInfo
): BotAuthorizationResult {
): BotAuthResult {
return block(authComponent, bot)
}
}
@ -126,7 +126,7 @@ public interface BotAuthorization {
}
@NotStableForInheritance
public interface BotAuthorizationResult
public interface BotAuthResult
@NotStableForInheritance
public interface BotAuthInfo {
@ -137,9 +137,9 @@ public interface BotAuthInfo {
@NotStableForInheritance
public interface BotAuthComponent {
public suspend fun authByPassword(password: String): BotAuthorizationResult
public suspend fun authByPassword(passwordMd5: ByteArray): BotAuthorizationResult
public suspend fun authByQRCode(): BotAuthorizationResult
public suspend fun authByPassword(password: String): BotAuthResult
public suspend fun authByPassword(passwordMd5: ByteArray): BotAuthResult
public suspend fun authByQRCode(): BotAuthResult
}
@ -150,7 +150,7 @@ public interface BotAuthComponent {
@NotStableForInheritance
@MiraiInternalApi
public interface MiraiInternalBotAuthComponent : BotAuthComponent {
public suspend fun authByPassword(passwordMd5: SecretsProtection.EscapedByteBuffer): BotAuthorizationResult
public suspend fun authByPassword(passwordMd5: SecretsProtection.EscapedByteBuffer): BotAuthResult
}
@NotStableForInheritance
@ -164,9 +164,9 @@ public interface MiraiInternalBotAuthorization : BotAuthorization {
bot: BotAuthInfo,
): SecretsProtection.EscapedByteBuffer
public suspend fun authorize(authComponent: MiraiInternalBotAuthComponent, bot: BotAuthInfo): BotAuthorizationResult
public suspend fun authorize(authComponent: MiraiInternalBotAuthComponent, bot: BotAuthInfo): BotAuthResult
override suspend fun authorize(authComponent: BotAuthComponent, bot: BotAuthInfo): BotAuthorizationResult {
override suspend fun authorize(authComponent: BotAuthComponent, bot: BotAuthInfo): BotAuthResult {
return authorize(authComponent as MiraiInternalBotAuthComponent, bot)
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@ -15,8 +15,8 @@ import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import net.mamoe.mirai.auth.BotAuthInfo
import net.mamoe.mirai.auth.BotAuthResult
import net.mamoe.mirai.auth.BotAuthorization
import net.mamoe.mirai.auth.BotAuthorizationResult
import net.mamoe.mirai.auth.MiraiInternalBotAuthComponent
import net.mamoe.mirai.internal.network.Packet
import net.mamoe.mirai.internal.network.QQAndroidClient
@ -322,7 +322,7 @@ internal class SsoProcessorImpl(
}
val botAuthorizationResult: BotAuthorizationResult
val botAuthResult: BotAuthResult
}
internal class AuthControl(
@ -342,12 +342,12 @@ internal class SsoProcessorImpl(
@Volatile
private var isCompleted = false
private val rsp = object : BotAuthorizationResult {}
private val rsp = object : BotAuthResult {}
@Suppress("RemoveExplicitTypeArguments")
@OptIn(TestOnly::class)
private val authComponent = object : SsoProcessorAuthComponent {
override val botAuthorizationResult: BotAuthorizationResult get() = rsp
override val botAuthResult: BotAuthResult get() = rsp
override suspend fun emit(method: AuthMethod) {
logger.verbose { "[AuthControl/emit] Trying emit $method" }
@ -370,20 +370,20 @@ internal class SsoProcessorImpl(
logger.verbose { "[AuthControl/emit] Authorization resumed after $method" }
}
override suspend fun authByPassword(passwordMd5: SecretsProtection.EscapedByteBuffer): BotAuthorizationResult {
override suspend fun authByPassword(passwordMd5: SecretsProtection.EscapedByteBuffer): BotAuthResult {
emit(AuthMethod.Pwd(passwordMd5))
return rsp
}
override suspend fun authByPassword(password: String): BotAuthorizationResult {
override suspend fun authByPassword(password: String): BotAuthResult {
return authByPassword(password.md5())
}
override suspend fun authByPassword(passwordMd5: ByteArray): BotAuthorizationResult {
override suspend fun authByPassword(passwordMd5: ByteArray): BotAuthResult {
return authByPassword(SecretsProtection.EscapedByteBuffer(passwordMd5))
}
override suspend fun authByQRCode(): BotAuthorizationResult {
override suspend fun authByQRCode(): BotAuthResult {
emit(AuthMethod.QRCode)
return rsp
}

View File

@ -13,8 +13,8 @@ import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.yield
import net.mamoe.mirai.auth.BotAuthComponent
import net.mamoe.mirai.auth.BotAuthInfo
import net.mamoe.mirai.auth.BotAuthResult
import net.mamoe.mirai.auth.BotAuthorization
import net.mamoe.mirai.auth.BotAuthorizationResult
import net.mamoe.mirai.internal.network.components.SsoProcessorContext
import net.mamoe.mirai.internal.network.components.SsoProcessorImpl
import net.mamoe.mirai.internal.network.framework.AbstractCommonNHTest
@ -53,7 +53,7 @@ internal class BotAuthControlTest : AbstractCommonNHTest() {
fun `auth test`() = runTest {
val control = SsoProcessorImpl.AuthControl(botAuthInfo, object : BotAuthorization {
override suspend fun authorize(authComponent: BotAuthComponent, bot: BotAuthInfo): BotAuthorizationResult {
override suspend fun authorize(authComponent: BotAuthComponent, bot: BotAuthInfo): BotAuthResult {
return authComponent.authByPassword(EMPTY_BYTE_ARRAY)
}
}, bot.logger, backgroundScope)
@ -68,7 +68,7 @@ internal class BotAuthControlTest : AbstractCommonNHTest() {
fun `test auth failed and reselect`() = runTest {
val control = SsoProcessorImpl.AuthControl(botAuthInfo, object : BotAuthorization {
override suspend fun authorize(authComponent: BotAuthComponent, bot: BotAuthInfo): BotAuthorizationResult {
override suspend fun authorize(authComponent: BotAuthComponent, bot: BotAuthInfo): BotAuthResult {
assertFails { authComponent.authByPassword(EMPTY_BYTE_ARRAY); println("!") }
println("114514")
return authComponent.authByPassword(EMPTY_BYTE_ARRAY)
@ -87,7 +87,7 @@ internal class BotAuthControlTest : AbstractCommonNHTest() {
fun `failed when login complete`() = runTest {
val control = SsoProcessorImpl.AuthControl(botAuthInfo, object : BotAuthorization {
override suspend fun authorize(authComponent: BotAuthComponent, bot: BotAuthInfo): BotAuthorizationResult {
override suspend fun authorize(authComponent: BotAuthComponent, bot: BotAuthInfo): BotAuthResult {
val rsp = authComponent.authByPassword(EMPTY_BYTE_ARRAY)
assertFails { authComponent.authByPassword(EMPTY_BYTE_ARRAY) }
assertFails { authComponent.authByPassword(EMPTY_BYTE_ARRAY) }

View File

@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
@ -14,7 +14,7 @@ package net.mamoe.mirai.internal.network.framework
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import net.mamoe.mirai.auth.BotAuthInfo
import net.mamoe.mirai.auth.BotAuthorizationResult
import net.mamoe.mirai.auth.BotAuthResult
import net.mamoe.mirai.auth.MiraiInternalBotAuthComponent
import net.mamoe.mirai.internal.*
import net.mamoe.mirai.internal.contact.uin
@ -123,22 +123,22 @@ internal abstract class AbstractRealNetworkHandlerTest<H : NetworkHandler> : Abs
override val configuration: BotConfiguration
get() = bot.configuration
}
val rsp = object : BotAuthorizationResult {}
val rsp = object : BotAuthResult {}
val botAuthComponents = object : MiraiInternalBotAuthComponent {
override suspend fun authByPassword(passwordMd5: SecretsProtection.EscapedByteBuffer): BotAuthorizationResult {
override suspend fun authByPassword(passwordMd5: SecretsProtection.EscapedByteBuffer): BotAuthResult {
return rsp
}
override suspend fun authByPassword(password: String): BotAuthorizationResult {
override suspend fun authByPassword(password: String): BotAuthResult {
return authByPassword(password.md5())
}
override suspend fun authByPassword(passwordMd5: ByteArray): BotAuthorizationResult {
override suspend fun authByPassword(passwordMd5: ByteArray): BotAuthResult {
return authByPassword(SecretsProtection.EscapedByteBuffer(passwordMd5))
}
override suspend fun authByQRCode(): BotAuthorizationResult {
override suspend fun authByQRCode(): BotAuthResult {
TODO("Not yet implemented")
}