diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/EnvelopeProtoMapper.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/EnvelopeProtoMapper.kt index 7f8b2b56267..7471228ec90 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/EnvelopeProtoMapper.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/EnvelopeProtoMapper.kt @@ -18,6 +18,7 @@ package com.wire.kalium.network.api.base.authenticated.message +import com.wire.kalium.protobuf.otr.ClientId import com.wire.kalium.protobuf.otr.ClientMismatchStrategy import com.wire.kalium.protobuf.otr.QualifiedNewOtrMessage import com.wire.kalium.protobuf.otr.QualifiedUserEntry @@ -35,8 +36,8 @@ internal class EnvelopeProtoMapperImpl : EnvelopeProtoMapper { private val otrClientEntryMapper = OtrClientEntryMapper() private val otrUserIdMapper = provideOtrUserIdMapper() - private val otrClientIdMapper = OtrClientIdMapper() + @OptIn(ExperimentalStdlibApi::class) override fun encodeToProtobuf(envelopeParameters: MessageApi.Parameters.QualifiedDefaultParameters): ByteArray { val qualifiedEntries = envelopeParameters.recipients.entries.groupBy({ it.key.domain }) { userEntry -> val clientEntries = userEntry.value.entries.map(otrClientEntryMapper::toOtrClientEntry) @@ -81,7 +82,7 @@ internal class EnvelopeProtoMapperImpl : EnvelopeProtoMapper { return QualifiedNewOtrMessage( recipients = qualifiedEntries, - sender = otrClientIdMapper.toOtrClientId(envelopeParameters.sender), + sender = ClientId(envelopeParameters.sender.hexToLong()), blob = envelopeParameters.externalBlob?.let { ByteArr(it) }, clientMismatchStrategy = strategy, nativePush = envelopeParameters.nativePush, diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/OtrClientEntryMapper.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/OtrClientEntryMapper.kt index a689cdf811d..bf551473c4e 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/OtrClientEntryMapper.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/OtrClientEntryMapper.kt @@ -19,13 +19,14 @@ package com.wire.kalium.network.api.base.authenticated.message import com.wire.kalium.protobuf.otr.ClientEntry +import com.wire.kalium.protobuf.otr.ClientId import pbandk.ByteArr internal class OtrClientEntryMapper { - private val clientIdMapper = OtrClientIdMapper() + @OptIn(ExperimentalStdlibApi::class) fun toOtrClientEntry(clientPayload: Map.Entry): ClientEntry = ClientEntry( - client = clientIdMapper.toOtrClientId(clientPayload.key), + client = ClientId(clientPayload.key.hexToLong()), text = ByteArr(clientPayload.value), ) } diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/OtrClientIdMapper.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/OtrClientIdMapper.kt deleted file mode 100644 index e3a9fdadc4c..00000000000 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/message/OtrClientIdMapper.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Wire - * Copyright (C) 2023 Wire Swiss GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - */ - -package com.wire.kalium.network.api.base.authenticated.message - -import com.wire.kalium.protobuf.otr.ClientId - -internal class OtrClientIdMapper { - fun toOtrClientId(clientId: String): ClientId = ClientId(clientId.decodeHexToLong()) -} - -private fun String.decodeHexToLong(): Long { - - @Suppress("MagicNumber") - fun unsignedLong(mostSignificantBits: Long, leastSignificantBits: Long) = - (mostSignificantBits shl 32) or leastSignificantBits - - val a = this.padStart(length = 16, '0').chunked(size = 8) { - it.toString().toLongOrNull(radix = 16) ?: 0 - } - - return unsignedLong(a[0], a[1]) -} diff --git a/network/src/commonTest/kotlin/com/wire/kalium/model/QualifiedSendMessageRequestJson.kt b/network/src/commonTest/kotlin/com/wire/kalium/model/QualifiedSendMessageRequestJson.kt index 921d3398062..b05a77611d1 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/model/QualifiedSendMessageRequestJson.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/model/QualifiedSendMessageRequestJson.kt @@ -90,7 +90,7 @@ object QualifiedSendMessageRequestJson { val validDefaultParameters = ValidJsonProvider( MessageApi.Parameters.QualifiedDefaultParameters( - sender = "sender-client-it", + sender = USER_1_CLIENT_1, externalBlob = "blob-id".toByteArray(), nativePush = true, recipients = mapOf(),