Skip to content

Commit

Permalink
🔨 Encrypted binary data does not need to be base64 encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang committed Feb 13, 2024
1 parent d7d816d commit 0826ffc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.clipevery.dto.sync

import com.clipevery.serializer.Base64MimeByteArraySerializer
import com.clipevery.serializer.Base64ByteArraySerializer
import kotlinx.serialization.Serializable

@Serializable
data class DataContent(
@Serializable(with = Base64MimeByteArraySerializer::class) val data: ByteArray
@Serializable(with = Base64ByteArraySerializer::class) val data: ByteArray
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

object Base64MimeByteArraySerializer: KSerializer<ByteArray> {
object Base64ByteArraySerializer: KSerializer<ByteArray> {

override val descriptor: SerialDescriptor = buildClassSerialDescriptor("ByteArray") {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clipevery.utils

import com.clipevery.serializer.Base64MimeByteArraySerializer
import com.clipevery.serializer.Base64ByteArraySerializer
import com.clipevery.serializer.IdentityKeySerializer
import com.clipevery.serializer.PreKeyBundleSerializer
import kotlinx.serialization.json.Json
Expand All @@ -13,7 +13,7 @@ object JsonUtils {

val JSON: Json = Json {
serializersModule = SerializersModule {
serializersModuleOf(ByteArray::class, Base64MimeByteArraySerializer)
serializersModuleOf(ByteArray::class, Base64ByteArraySerializer)
serializersModuleOf(PreKeyBundle::class, PreKeyBundleSerializer)
serializersModuleOf(IdentityKey::class, IdentityKeySerializer)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.clipevery.net.plugin

import com.clipevery.Dependencies
import com.clipevery.serializer.Base64MimeByteArraySerializer
import com.clipevery.utils.JsonUtils
import io.ktor.server.application.ApplicationPlugin
import io.ktor.server.application.createApplicationPlugin
import io.ktor.server.application.hooks.ReceiveRequestBytes
Expand Down Expand Up @@ -30,9 +28,7 @@ val SignalDecryption: ApplicationPlugin<SignalDecryptionConfig> = createApplicat
if (signal == "1") {
call.request.path()
return@on application.writer {
val base64Content = body.readRemaining().readBytes()
val originalString = String(base64Content, Charsets.UTF_8)
val encryptedContent = JsonUtils.JSON.decodeFromString(Base64MimeByteArraySerializer, originalString)
val encryptedContent = body.readRemaining().readBytes()
val signalProtocolAddress = SignalProtocolAddress(appInstanceId, 1)
val signalMessage = SignalMessage(encryptedContent)
val sessionCipher = SessionCipher(signalProtocolStore, signalProtocolAddress)
Expand Down

0 comments on commit 0826ffc

Please sign in to comment.