mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[fleet] fix Base64 usages: allow non-padded input
Follows-up aff75c5e3eae2d6d33b65a18c1d89815e23bf997 which introduced an implicit mandatory padding by use of default `kotlin.io.encoding.Base64` object.
Utility decoder is now provided to make the choice explicit.
Also reverts PluginSerialization.kt, it seems withPadding isn't supported (probably used somewhere in plugin with kotlin version < 2.0, while it's marked `@SinceKotlin("2.0")`)
GitOrigin-RevId: 3f9a639e2cbf58e30293da9c87e3e4bd0824796b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
04483f7b9e
commit
1aa5074b00
@@ -24,7 +24,6 @@ import kotlinx.serialization.modules.SerializersModule
|
||||
import kotlinx.serialization.serializer
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.io.encoding.Base64
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KClassifier
|
||||
@@ -360,12 +359,12 @@ class Blob(val bytes: ByteArray) {
|
||||
object BlobSerializer : DataSerializer<Blob, String>(String.serializer()) {
|
||||
@OptIn(ExperimentalEncodingApi::class)
|
||||
override fun fromData(data: String): Blob {
|
||||
return Blob(Base64.decode(data))
|
||||
return Blob(Base64WithOptionalPadding.decode(data))
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalEncodingApi::class)
|
||||
override fun toData(value: Blob): String {
|
||||
return Base64.encode(value.bytes)
|
||||
return Base64WithOptionalPadding.encode(value.bytes)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package fleet.util
|
||||
|
||||
import kotlin.io.encoding.Base64
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
|
||||
/*
|
||||
* Following functions are used to replace jvm specific byte array to string conversion that explicitly specified UTF-8 as charset.
|
||||
*/
|
||||
@@ -15,3 +18,11 @@ fun ByteArray.decodeToStringUtf8(
|
||||
endIndex: Int = this.size,
|
||||
throwOnInvalidSequence: Boolean = false
|
||||
): String = decodeToString(startIndex, endIndex, throwOnInvalidSequence)
|
||||
|
||||
// Replaces java.util.Base64.getDecoder(), which did not require padding on decoding
|
||||
@OptIn(ExperimentalEncodingApi::class)
|
||||
val Base64WithOptionalPadding = Base64.withPadding(Base64.PaddingOption.PRESENT_OPTIONAL)
|
||||
|
||||
// Replaces java.util.Base64.getUrlDecoder(), which did not require padding on decoding
|
||||
@OptIn(ExperimentalEncodingApi::class)
|
||||
val UrlSafeBase64WithOptionalPadding = Base64.UrlSafe.withPadding(Base64.PaddingOption.PRESENT_OPTIONAL)
|
||||
|
||||
Reference in New Issue
Block a user