From 71a47af43cd212fa6d5ceae3097d386016040c21 Mon Sep 17 00:00:00 2001 From: Infendro Date: Mon, 10 Nov 2025 18:59:53 +0100 Subject: [PATCH 1/6] refactor encodings --- .../kotlin/com/infendro/encoding/Base32.kt | 20 +++++------ .../kotlin/com/infendro/encoding/Base64.kt | 28 +++++++-------- .../kotlin/com/infendro/encoding/Binary.kt | 12 +++---- .../kotlin/com/infendro/encoding/Encoding.kt | 36 +++++++++---------- .../kotlin/com/infendro/encoding/Hex.kt | 14 ++++---- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/commonMain/kotlin/com/infendro/encoding/Base32.kt b/src/commonMain/kotlin/com/infendro/encoding/Base32.kt index 0977652..5bc8c73 100644 --- a/src/commonMain/kotlin/com/infendro/encoding/Base32.kt +++ b/src/commonMain/kotlin/com/infendro/encoding/Base32.kt @@ -1,17 +1,17 @@ package com.infendro.encoding object Base32 : Encoding() { - private val CHARACTERS = arrayOf( - 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, - 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, - 0x59, 0x5a, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + private val CHARACTERS = ubyteArrayOf( + 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, + 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, + 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, + 0x59U, 0x5aU, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, ) - private const val PADDING: Byte = 0x3d + private const val PADDING: UByte = 0x3dU override fun encode( - bytes: ByteArray, - ): ByteArray { + bytes: UByteArray, + ): UByteArray { return encode( bytes, CHARACTERS, @@ -20,8 +20,8 @@ object Base32 : Encoding() { } override fun decode( - bytes: ByteArray, - ): ByteArray { + bytes: UByteArray, + ): UByteArray { return decode( bytes, CHARACTERS, diff --git a/src/commonMain/kotlin/com/infendro/encoding/Base64.kt b/src/commonMain/kotlin/com/infendro/encoding/Base64.kt index 85fc80c..e857105 100644 --- a/src/commonMain/kotlin/com/infendro/encoding/Base64.kt +++ b/src/commonMain/kotlin/com/infendro/encoding/Base64.kt @@ -1,21 +1,21 @@ package com.infendro.encoding object Base64 : Encoding() { - private val CHARACTERS = arrayOf( - 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, - 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, - 0x59, 0x5a, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, - 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, - 0x77, 0x78, 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, - 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2b, 0x2f, + private val CHARACTERS = ubyteArrayOf( + 0x41U, 0x42U, 0x43U, 0x44U, 0x45U, 0x46U, 0x47U, 0x48U, + 0x49U, 0x4aU, 0x4bU, 0x4cU, 0x4dU, 0x4eU, 0x4fU, 0x50U, + 0x51U, 0x52U, 0x53U, 0x54U, 0x55U, 0x56U, 0x57U, 0x58U, + 0x59U, 0x5aU, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, + 0x67U, 0x68U, 0x69U, 0x6aU, 0x6bU, 0x6cU, 0x6dU, 0x6eU, + 0x6fU, 0x70U, 0x71U, 0x72U, 0x73U, 0x74U, 0x75U, 0x76U, + 0x77U, 0x78U, 0x79U, 0x7aU, 0x30U, 0x31U, 0x32U, 0x33U, + 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x2bU, 0x2fU, ) - private const val PADDING: Byte = 0x3d + private const val PADDING: UByte = 0x3dU override fun encode( - bytes: ByteArray, - ): ByteArray { + bytes: UByteArray, + ): UByteArray { return encode( bytes, CHARACTERS, @@ -24,8 +24,8 @@ object Base64 : Encoding() { } override fun decode( - bytes: ByteArray, - ): ByteArray { + bytes: UByteArray, + ): UByteArray { return decode( bytes, CHARACTERS, diff --git a/src/commonMain/kotlin/com/infendro/encoding/Binary.kt b/src/commonMain/kotlin/com/infendro/encoding/Binary.kt index 78e0bb0..aecf757 100644 --- a/src/commonMain/kotlin/com/infendro/encoding/Binary.kt +++ b/src/commonMain/kotlin/com/infendro/encoding/Binary.kt @@ -1,13 +1,13 @@ package com.infendro.encoding object Binary : Encoding() { - private val CHARACTERS = arrayOf( - 0x30, 0x31, + private val CHARACTERS = ubyteArrayOf( + 0x30U, 0x31U, ) override fun encode( - bytes: ByteArray, - ): ByteArray { + bytes: UByteArray, + ): UByteArray { return encode( bytes, CHARACTERS, @@ -15,8 +15,8 @@ object Binary : Encoding() { } override fun decode( - bytes: ByteArray, - ): ByteArray { + bytes: UByteArray, + ): UByteArray { return decode( bytes, CHARACTERS, diff --git a/src/commonMain/kotlin/com/infendro/encoding/Encoding.kt b/src/commonMain/kotlin/com/infendro/encoding/Encoding.kt index 75c9814..c3aebe9 100644 --- a/src/commonMain/kotlin/com/infendro/encoding/Encoding.kt +++ b/src/commonMain/kotlin/com/infendro/encoding/Encoding.kt @@ -6,28 +6,28 @@ import kotlin.math.pow sealed class Encoding { abstract fun encode( - bytes: ByteArray, - ): ByteArray + bytes: UByteArray, + ): UByteArray abstract fun decode( - bytes: ByteArray, - ): ByteArray + bytes: UByteArray, + ): UByteArray protected fun encode( - bytes: ByteArray, - characters: Array, - padding: Byte? = null, - ): ByteArray { + bytes: UByteArray, + characters: UByteArray, + padding: UByte? = null, + ): UByteArray { val length = log2(characters.size).toInt() val mask = (2.0.pow(length) - 1).toUInt() - val encoded = mutableListOf() + val encoded = mutableListOf() var buffer = 0U var bits = 0 for (byte in bytes) { - buffer = (buffer shl 8) + byte.toUByte() + buffer = (buffer shl 8) + byte bits += 8 while (bits >= length) { @@ -52,18 +52,18 @@ sealed class Encoding { } } - return encoded.toByteArray() + return encoded.toUByteArray() } protected fun decode( - bytes: ByteArray, - characters: Array, - padding: Byte? = null, - ): ByteArray { + bytes: UByteArray, + characters: UByteArray, + padding: UByte? = null, + ): UByteArray { val length = log2(characters.size).toInt() val mask = 0xFFU - val decoded = mutableListOf() + val decoded = mutableListOf() var buffer = 0U var bits = 0 @@ -79,7 +79,7 @@ sealed class Encoding { if (bits >= 8) { val offset = bits - 8 - val character = (buffer shr offset).toByte() + val character = (buffer shr offset).toUByte() buffer = buffer and (mask shl offset).inv() bits -= 8 @@ -87,6 +87,6 @@ sealed class Encoding { } } - return decoded.toByteArray() + return decoded.toUByteArray() } } diff --git a/src/commonMain/kotlin/com/infendro/encoding/Hex.kt b/src/commonMain/kotlin/com/infendro/encoding/Hex.kt index 5c4a645..f2acbd5 100644 --- a/src/commonMain/kotlin/com/infendro/encoding/Hex.kt +++ b/src/commonMain/kotlin/com/infendro/encoding/Hex.kt @@ -1,14 +1,14 @@ package com.infendro.encoding object Hex : Encoding() { - private val CHARACTERS = arrayOf( - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + private val CHARACTERS = ubyteArrayOf( + 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, + 0x38U, 0x39U, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, ) override fun encode( - bytes: ByteArray, - ): ByteArray { + bytes: UByteArray, + ): UByteArray { return encode( bytes, CHARACTERS, @@ -16,8 +16,8 @@ object Hex : Encoding() { } override fun decode( - bytes: ByteArray, - ): ByteArray { + bytes: UByteArray, + ): UByteArray { return decode( bytes, CHARACTERS, From 52a1ca6553fae90475304c5437d86eb617e25fd1 Mon Sep 17 00:00:00 2001 From: Infendro Date: Mon, 10 Nov 2025 19:00:28 +0100 Subject: [PATCH 2/6] add opt-in --- build.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 749ffbd..7fe021e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,6 +16,10 @@ kotlin { nodejs() } linuxX64() + + compilerOptions { + freeCompilerArgs.add("-opt-in=kotlin.ExperimentalUnsignedTypes") + } } publishing { From 12344283f79770c9df97d279f798be8808e8f8ab Mon Sep 17 00:00:00 2001 From: Infendro Date: Tue, 18 Nov 2025 11:21:46 +0100 Subject: [PATCH 3/6] implement Base8 encoding, rename Binary and Hex encodings --- .../infendro/encoding/{Hex.kt => Base16.kt} | 16 +++--------- .../kotlin/com/infendro/encoding/Base2.kt | 15 +++++++++++ .../kotlin/com/infendro/encoding/Base32.kt | 16 ++---------- .../kotlin/com/infendro/encoding/Base64.kt | 16 ++---------- .../kotlin/com/infendro/encoding/Base8.kt | 15 +++++++++++ .../kotlin/com/infendro/encoding/Binary.kt | 25 ------------------- .../kotlin/com/infendro/encoding/Encoding.kt | 2 +- 7 files changed, 38 insertions(+), 67 deletions(-) rename src/commonMain/kotlin/com/infendro/encoding/{Hex.kt => Base16.kt} (57%) create mode 100644 src/commonMain/kotlin/com/infendro/encoding/Base2.kt create mode 100644 src/commonMain/kotlin/com/infendro/encoding/Base8.kt delete mode 100644 src/commonMain/kotlin/com/infendro/encoding/Binary.kt diff --git a/src/commonMain/kotlin/com/infendro/encoding/Hex.kt b/src/commonMain/kotlin/com/infendro/encoding/Base16.kt similarity index 57% rename from src/commonMain/kotlin/com/infendro/encoding/Hex.kt rename to src/commonMain/kotlin/com/infendro/encoding/Base16.kt index f2acbd5..4c23230 100644 --- a/src/commonMain/kotlin/com/infendro/encoding/Hex.kt +++ b/src/commonMain/kotlin/com/infendro/encoding/Base16.kt @@ -1,6 +1,6 @@ package com.infendro.encoding -object Hex : Encoding() { +object Base16 : Encoding() { private val CHARACTERS = ubyteArrayOf( 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U, @@ -8,19 +8,9 @@ object Hex : Encoding() { override fun encode( bytes: UByteArray, - ): UByteArray { - return encode( - bytes, - CHARACTERS, - ) - } + ) = encode(bytes, CHARACTERS) override fun decode( bytes: UByteArray, - ): UByteArray { - return decode( - bytes, - CHARACTERS, - ) - } + ) = decode(bytes, CHARACTERS) } diff --git a/src/commonMain/kotlin/com/infendro/encoding/Base2.kt b/src/commonMain/kotlin/com/infendro/encoding/Base2.kt new file mode 100644 index 0000000..a6de71b --- /dev/null +++ b/src/commonMain/kotlin/com/infendro/encoding/Base2.kt @@ -0,0 +1,15 @@ +package com.infendro.encoding + +object Base2 : Encoding() { + private val CHARACTERS = ubyteArrayOf( + 0x30U, 0x31U, + ) + + override fun encode( + bytes: UByteArray, + ) = encode(bytes, CHARACTERS) + + override fun decode( + bytes: UByteArray, + ) = decode(bytes, CHARACTERS) +} diff --git a/src/commonMain/kotlin/com/infendro/encoding/Base32.kt b/src/commonMain/kotlin/com/infendro/encoding/Base32.kt index 5bc8c73..007471f 100644 --- a/src/commonMain/kotlin/com/infendro/encoding/Base32.kt +++ b/src/commonMain/kotlin/com/infendro/encoding/Base32.kt @@ -11,21 +11,9 @@ object Base32 : Encoding() { override fun encode( bytes: UByteArray, - ): UByteArray { - return encode( - bytes, - CHARACTERS, - PADDING, - ) - } + ) = encode(bytes, CHARACTERS, PADDING) override fun decode( bytes: UByteArray, - ): UByteArray { - return decode( - bytes, - CHARACTERS, - PADDING, - ) - } + ) = decode(bytes, CHARACTERS, PADDING) } diff --git a/src/commonMain/kotlin/com/infendro/encoding/Base64.kt b/src/commonMain/kotlin/com/infendro/encoding/Base64.kt index e857105..bcf1c6c 100644 --- a/src/commonMain/kotlin/com/infendro/encoding/Base64.kt +++ b/src/commonMain/kotlin/com/infendro/encoding/Base64.kt @@ -15,21 +15,9 @@ object Base64 : Encoding() { override fun encode( bytes: UByteArray, - ): UByteArray { - return encode( - bytes, - CHARACTERS, - PADDING, - ) - } + ) = encode(bytes, CHARACTERS, PADDING) override fun decode( bytes: UByteArray, - ): UByteArray { - return decode( - bytes, - CHARACTERS, - PADDING, - ) - } + ) = decode(bytes, CHARACTERS, PADDING) } diff --git a/src/commonMain/kotlin/com/infendro/encoding/Base8.kt b/src/commonMain/kotlin/com/infendro/encoding/Base8.kt new file mode 100644 index 0000000..ac9dccc --- /dev/null +++ b/src/commonMain/kotlin/com/infendro/encoding/Base8.kt @@ -0,0 +1,15 @@ +package com.infendro.encoding + +object Base8 : Encoding() { + private val CHARACTERS = ubyteArrayOf( + 0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, + ) + + override fun encode( + bytes: UByteArray, + ) = encode(bytes, CHARACTERS) + + override fun decode( + bytes: UByteArray, + ) = decode(bytes, CHARACTERS) +} diff --git a/src/commonMain/kotlin/com/infendro/encoding/Binary.kt b/src/commonMain/kotlin/com/infendro/encoding/Binary.kt deleted file mode 100644 index aecf757..0000000 --- a/src/commonMain/kotlin/com/infendro/encoding/Binary.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.infendro.encoding - -object Binary : Encoding() { - private val CHARACTERS = ubyteArrayOf( - 0x30U, 0x31U, - ) - - override fun encode( - bytes: UByteArray, - ): UByteArray { - return encode( - bytes, - CHARACTERS, - ) - } - - override fun decode( - bytes: UByteArray, - ): UByteArray { - return decode( - bytes, - CHARACTERS, - ) - } -} diff --git a/src/commonMain/kotlin/com/infendro/encoding/Encoding.kt b/src/commonMain/kotlin/com/infendro/encoding/Encoding.kt index c3aebe9..211a271 100644 --- a/src/commonMain/kotlin/com/infendro/encoding/Encoding.kt +++ b/src/commonMain/kotlin/com/infendro/encoding/Encoding.kt @@ -61,7 +61,7 @@ sealed class Encoding { padding: UByte? = null, ): UByteArray { val length = log2(characters.size).toInt() - val mask = 0xFFU + val mask = 0xffU val decoded = mutableListOf() From 9e4109c9f30b01a72df4031735a37f6e79d583d7 Mon Sep 17 00:00:00 2001 From: Infendro Date: Tue, 18 Nov 2025 11:22:05 +0100 Subject: [PATCH 4/6] implement tests --- build.gradle.kts | 6 +++ gradle/libs.versions.toml | 3 ++ .../kotlin/com/infendro/encoding/Base16.kt | 33 +++++++++++++++ .../kotlin/com/infendro/encoding/Base2.kt | 42 +++++++++++++++++++ .../kotlin/com/infendro/encoding/Base32.kt | 33 +++++++++++++++ .../kotlin/com/infendro/encoding/Base64.kt | 32 ++++++++++++++ .../kotlin/com/infendro/encoding/Base8.kt | 34 +++++++++++++++ 7 files changed, 183 insertions(+) create mode 100644 src/commonTest/kotlin/com/infendro/encoding/Base16.kt create mode 100644 src/commonTest/kotlin/com/infendro/encoding/Base2.kt create mode 100644 src/commonTest/kotlin/com/infendro/encoding/Base32.kt create mode 100644 src/commonTest/kotlin/com/infendro/encoding/Base64.kt create mode 100644 src/commonTest/kotlin/com/infendro/encoding/Base8.kt diff --git a/build.gradle.kts b/build.gradle.kts index 7fe021e..d42cab3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,6 +17,12 @@ kotlin { } linuxX64() + sourceSets { + commonTest.dependencies { + implementation(libs.test) + } + } + compilerOptions { freeCompilerArgs.add("-opt-in=kotlin.ExperimentalUnsignedTypes") } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bb704f3..7b812f8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,3 +3,6 @@ kotlin = "2.1.20" [plugins] multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } + +[libraries] +test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base16.kt b/src/commonTest/kotlin/com/infendro/encoding/Base16.kt new file mode 100644 index 0000000..87e6888 --- /dev/null +++ b/src/commonTest/kotlin/com/infendro/encoding/Base16.kt @@ -0,0 +1,33 @@ +package com.infendro.encoding + +import kotlin.test.Test +import kotlin.test.assertContentEquals + +class `Base16 Test` { + val encoding: Encoding + get() = Base16 + + val `Hello World!` = ubyteArrayOf( + 0x48U, 0x65U, 0x6cU, 0x6cU, + 0x6fU, 0x20U, 0x57U, 0x6fU, + 0x72U, 0x6cU, 0x64U, 0x21U, + ) + + @Test + fun `encode empty ByteArray`() { + val expected = ubyteArrayOf() + val actual = encoding.encode(ubyteArrayOf()) + assertContentEquals(expected, actual) + } + + @Test + fun `encode "Hello, World!"`() { + val expected = ubyteArrayOf( + 0x34U, 0x38U, 0x36U, 0x35U, 0x36U, 0x63U, 0x36U, 0x63U, + 0x36U, 0x66U, 0x32U, 0x30U, 0x35U, 0x37U, 0x36U, 0x66U, + 0x37U, 0x32U, 0x36U, 0x63U, 0x36U, 0x34U, 0x32U, 0x31U, + ) + val actual = encoding.encode(`Hello World!`) + assertContentEquals(expected, actual) + } +} diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base2.kt b/src/commonTest/kotlin/com/infendro/encoding/Base2.kt new file mode 100644 index 0000000..3b638e6 --- /dev/null +++ b/src/commonTest/kotlin/com/infendro/encoding/Base2.kt @@ -0,0 +1,42 @@ +package com.infendro.encoding + +import kotlin.test.Test +import kotlin.test.assertContentEquals + +class `Base2 Test` { + val encoding: Encoding + get() = Base2 + + val `Hello World!` = ubyteArrayOf( + 0x48U, 0x65U, 0x6cU, 0x6cU, + 0x6fU, 0x20U, 0x57U, 0x6fU, + 0x72U, 0x6cU, 0x64U, 0x21U, + ) + + @Test + fun `encode empty ByteArray`() { + val expected = ubyteArrayOf() + val actual = encoding.encode(ubyteArrayOf()) + assertContentEquals(expected, actual) + } + + @Test + fun `encode "Hello, World!"`() { + val expected = ubyteArrayOf( + 0x30U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U, 0x30U, 0x30U, + 0x30U, 0x31U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U, 0x31U, + 0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x30U, 0x30U, + 0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x30U, 0x30U, + 0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x31U, 0x31U, + 0x30U, 0x30U, 0x31U, 0x30U, 0x30U, 0x30U, 0x30U, 0x30U, + 0x30U, 0x31U, 0x30U, 0x31U, 0x30U, 0x31U, 0x31U, 0x31U, + 0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x31U, 0x31U, + 0x30U, 0x31U, 0x31U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U, + 0x30U, 0x31U, 0x31U, 0x30U, 0x31U, 0x31U, 0x30U, 0x30U, + 0x30U, 0x31U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U, 0x30U, + 0x30U, 0x30U, 0x31U, 0x30U, 0x30U, 0x30U, 0x30U, 0x31U, + ) + val actual = encoding.encode(`Hello World!`) + assertContentEquals(expected, actual) + } +} diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base32.kt b/src/commonTest/kotlin/com/infendro/encoding/Base32.kt new file mode 100644 index 0000000..8b673f5 --- /dev/null +++ b/src/commonTest/kotlin/com/infendro/encoding/Base32.kt @@ -0,0 +1,33 @@ +package com.infendro.encoding + +import kotlin.test.Test +import kotlin.test.assertContentEquals + +class `Base32 Test` { + val encoding: Encoding + get() = Base32 + + val `Hello World!` = ubyteArrayOf( + 0x48U, 0x65U, 0x6cU, 0x6cU, + 0x6fU, 0x20U, 0x57U, 0x6fU, + 0x72U, 0x6cU, 0x64U, 0x21U, + ) + + @Test + fun `encode empty ByteArray`() { + val expected = ubyteArrayOf() + val actual = encoding.encode(ubyteArrayOf()) + assertContentEquals(expected, actual) + } + + @Test + fun `encode "Hello, World!"`() { + val expected = ubyteArrayOf( + 0x4aU, 0x42U, 0x53U, 0x57U, 0x59U, 0x33U, 0x44U, 0x50U, + 0x45U, 0x42U, 0x4cU, 0x57U, 0x36U, 0x34U, 0x54U, 0x4dU, + 0x4dU, 0x51U, 0x51U, 0x51U, 0x3dU, 0x3dU, 0x3dU, 0x3dU, + ) + val actual = encoding.encode(`Hello World!`) + assertContentEquals(expected, actual) + } +} diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base64.kt b/src/commonTest/kotlin/com/infendro/encoding/Base64.kt new file mode 100644 index 0000000..3fad608 --- /dev/null +++ b/src/commonTest/kotlin/com/infendro/encoding/Base64.kt @@ -0,0 +1,32 @@ +package com.infendro.encoding + +import kotlin.test.Test +import kotlin.test.assertContentEquals + +class `Base64 Test` { + val encoding: Encoding + get() = Base64 + + val `Hello World!` = ubyteArrayOf( + 0x48U, 0x65U, 0x6cU, 0x6cU, + 0x6fU, 0x20U, 0x57U, 0x6fU, + 0x72U, 0x6cU, 0x64U, 0x21U, + ) + + @Test + fun `encode empty ByteArray`() { + val expected = ubyteArrayOf() + val actual = encoding.encode(ubyteArrayOf()) + assertContentEquals(expected, actual) + } + + @Test + fun `encode "Hello, World!"`() { + val expected = ubyteArrayOf( + 0x53U, 0x47U, 0x56U, 0x73U, 0x62U, 0x47U, 0x38U, 0x67U, + 0x56U, 0x32U, 0x39U, 0x79U, 0x62U, 0x47U, 0x51U, 0x68U, + ) + val actual = encoding.encode(`Hello World!`) + assertContentEquals(expected, actual) + } +} diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base8.kt b/src/commonTest/kotlin/com/infendro/encoding/Base8.kt new file mode 100644 index 0000000..9f69400 --- /dev/null +++ b/src/commonTest/kotlin/com/infendro/encoding/Base8.kt @@ -0,0 +1,34 @@ +package com.infendro.encoding + +import kotlin.test.Test +import kotlin.test.assertContentEquals + +class `Base8 Test` { + val encoding: Encoding + get() = Base8 + + val `Hello World!` = ubyteArrayOf( + 0x48U, 0x65U, 0x6cU, 0x6cU, + 0x6fU, 0x20U, 0x57U, 0x6fU, + 0x72U, 0x6cU, 0x64U, 0x21U, + ) + + @Test + fun `encode empty ByteArray`() { + val expected = ubyteArrayOf() + val actual = encoding.encode(ubyteArrayOf()) + assertContentEquals(expected, actual) + } + + @Test + fun `encode "Hello, World!"`() { + val expected = ubyteArrayOf( + 0x32U, 0x32U, 0x30U, 0x36U, 0x32U, 0x35U, 0x35U, 0x34U, + 0x33U, 0x33U, 0x30U, 0x36U, 0x37U, 0x34U, 0x34U, 0x30U, + 0x32U, 0x35U, 0x36U, 0x36U, 0x37U, 0x35U, 0x36U, 0x32U, + 0x33U, 0x33U, 0x30U, 0x36U, 0x32U, 0x30U, 0x34U, 0x31U, + ) + val actual = encoding.encode(`Hello World!`) + assertContentEquals(expected, actual) + } +} From e40ef3168d4c265f46aa00f5a20d6b1db51c4654 Mon Sep 17 00:00:00 2001 From: Infendro Date: Tue, 18 Nov 2025 11:22:27 +0100 Subject: [PATCH 5/6] bump version to 1.2.0 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index d42cab3..2fb8f05 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ group = "com.infendro" -version = "1.1.0" +version = "1.2.0" repositories { mavenCentral() From 843013b7e7b21e13e97f13706dc39bdfe05970a2 Mon Sep 17 00:00:00 2001 From: Infendro Date: Tue, 18 Nov 2025 11:24:28 +0100 Subject: [PATCH 6/6] fix test naming --- src/commonTest/kotlin/com/infendro/encoding/Base16.kt | 2 +- src/commonTest/kotlin/com/infendro/encoding/Base2.kt | 2 +- src/commonTest/kotlin/com/infendro/encoding/Base32.kt | 2 +- src/commonTest/kotlin/com/infendro/encoding/Base64.kt | 2 +- src/commonTest/kotlin/com/infendro/encoding/Base8.kt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base16.kt b/src/commonTest/kotlin/com/infendro/encoding/Base16.kt index 87e6888..63d7c4b 100644 --- a/src/commonTest/kotlin/com/infendro/encoding/Base16.kt +++ b/src/commonTest/kotlin/com/infendro/encoding/Base16.kt @@ -21,7 +21,7 @@ class `Base16 Test` { } @Test - fun `encode "Hello, World!"`() { + fun `encode "Hello World!"`() { val expected = ubyteArrayOf( 0x34U, 0x38U, 0x36U, 0x35U, 0x36U, 0x63U, 0x36U, 0x63U, 0x36U, 0x66U, 0x32U, 0x30U, 0x35U, 0x37U, 0x36U, 0x66U, diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base2.kt b/src/commonTest/kotlin/com/infendro/encoding/Base2.kt index 3b638e6..b4fa689 100644 --- a/src/commonTest/kotlin/com/infendro/encoding/Base2.kt +++ b/src/commonTest/kotlin/com/infendro/encoding/Base2.kt @@ -21,7 +21,7 @@ class `Base2 Test` { } @Test - fun `encode "Hello, World!"`() { + fun `encode "Hello World!"`() { val expected = ubyteArrayOf( 0x30U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U, 0x30U, 0x30U, 0x30U, 0x31U, 0x31U, 0x30U, 0x30U, 0x31U, 0x30U, 0x31U, diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base32.kt b/src/commonTest/kotlin/com/infendro/encoding/Base32.kt index 8b673f5..76362c2 100644 --- a/src/commonTest/kotlin/com/infendro/encoding/Base32.kt +++ b/src/commonTest/kotlin/com/infendro/encoding/Base32.kt @@ -21,7 +21,7 @@ class `Base32 Test` { } @Test - fun `encode "Hello, World!"`() { + fun `encode "Hello World!"`() { val expected = ubyteArrayOf( 0x4aU, 0x42U, 0x53U, 0x57U, 0x59U, 0x33U, 0x44U, 0x50U, 0x45U, 0x42U, 0x4cU, 0x57U, 0x36U, 0x34U, 0x54U, 0x4dU, diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base64.kt b/src/commonTest/kotlin/com/infendro/encoding/Base64.kt index 3fad608..169591d 100644 --- a/src/commonTest/kotlin/com/infendro/encoding/Base64.kt +++ b/src/commonTest/kotlin/com/infendro/encoding/Base64.kt @@ -21,7 +21,7 @@ class `Base64 Test` { } @Test - fun `encode "Hello, World!"`() { + fun `encode "Hello World!"`() { val expected = ubyteArrayOf( 0x53U, 0x47U, 0x56U, 0x73U, 0x62U, 0x47U, 0x38U, 0x67U, 0x56U, 0x32U, 0x39U, 0x79U, 0x62U, 0x47U, 0x51U, 0x68U, diff --git a/src/commonTest/kotlin/com/infendro/encoding/Base8.kt b/src/commonTest/kotlin/com/infendro/encoding/Base8.kt index 9f69400..ce16791 100644 --- a/src/commonTest/kotlin/com/infendro/encoding/Base8.kt +++ b/src/commonTest/kotlin/com/infendro/encoding/Base8.kt @@ -21,7 +21,7 @@ class `Base8 Test` { } @Test - fun `encode "Hello, World!"`() { + fun `encode "Hello World!"`() { val expected = ubyteArrayOf( 0x32U, 0x32U, 0x30U, 0x36U, 0x32U, 0x35U, 0x35U, 0x34U, 0x33U, 0x33U, 0x30U, 0x36U, 0x37U, 0x34U, 0x34U, 0x30U,