Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Encrypted binary data does not need to be base64 encoded #313

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading