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

🔨 Base64 implementation using kotlin.io, better multiplatform equivalent implementation #2232

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
Expand Up @@ -5,6 +5,8 @@ import io.ktor.utils.io.core.*
import okio.Path
import okio.buffer
import okio.use
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi

expect fun getCodecsUtils(): CodecsUtils

Expand All @@ -20,9 +22,15 @@ interface CodecsUtils {

val sha256: Hasher

fun base64Encode(bytes: ByteArray): String
@OptIn(ExperimentalEncodingApi::class)
fun base64Encode(bytes: ByteArray): String {
return Base64.encode(bytes)
}

fun base64Decode(string: String): ByteArray
@OptIn(ExperimentalEncodingApi::class)
fun base64Decode(string: String): ByteArray {
return Base64.decode(string)
}

fun hash(bytes: ByteArray): String {
val (hash1, hash2) = CROSSPASTE_HASH.hash128x64(bytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.crosspaste.utils
import dev.whyoleg.cryptography.CryptographyProvider
import dev.whyoleg.cryptography.algorithms.SHA256
import java.io.ByteArrayOutputStream
import java.util.Base64

actual fun getCodecsUtils(): CodecsUtils {
return DesktopCodecsUtils
Expand All @@ -17,14 +16,6 @@ object DesktopCodecsUtils : CodecsUtils {

override val sha256 = provider.get(SHA256).hasher()

override fun base64Encode(bytes: ByteArray): String {
return Base64.getEncoder().encodeToString(bytes)
}

override fun base64Decode(string: String): ByteArray {
return Base64.getDecoder().decode(string)
}

override fun hashByArray(array: Array<String>): String {
if (array.isEmpty()) {
throw IllegalArgumentException("Array is empty")
Expand Down