From 4f04f4ae027ef0a71fa10861a239ebef021d28d2 Mon Sep 17 00:00:00 2001 From: Infendro Date: Sun, 15 Feb 2026 00:11:45 +0100 Subject: [PATCH] Remove unsigned support --- README.md | 2 +- build.gradle.kts | 8 ++------ gradle/libs.versions.toml | 6 +++--- .../kotlin/com/infendro/mac/HMAC.kt | 5 +++-- src/commonMain/kotlin/com/infendro/mac/MAC.kt | 19 +++++-------------- .../kotlin/com/infendro/mac/HMAC.kt | 16 ++++++---------- 6 files changed, 20 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index f392dd7..2b1a4b3 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ repositories { } dependencies { - implementation("com.infendro:mac:1.3.0") + implementation("com.infendro:mac:1.4.0") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 168c970..eadff65 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ import com.infendro.plugin.token import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl group = "com.infendro" -version = "1.3.0" +version = "1.4.0" plugins { alias(libs.plugins.infendro) @@ -31,17 +31,13 @@ kotlin { sourceSets { commonMain.dependencies { - implementation(libs.hash) implementation(libs.bytes) + implementation(libs.hash) } commonTest.dependencies { implementation(libs.test) } } - - compilerOptions { - freeCompilerArgs.add("-opt-in=kotlin.ExperimentalUnsignedTypes") - } } publishing.repositories { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 627e5eb..bbbe93a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,14 +1,14 @@ [versions] infendro = "1.1.0" kotlin = "2.3.0" -hash = "1.5.1" -bytes = "1.3.3" +bytes = "1.4.0" +hash = "1.6.0" [plugins] infendro = { id = "com.infendro.plugin", version.ref = "infendro" } multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } [libraries] -hash = { module = "com.infendro:hash", version.ref = "hash" } bytes = { module = "com.infendro:bytes", version.ref = "bytes" } +hash = { module = "com.infendro:hash", version.ref = "hash" } test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } diff --git a/src/commonMain/kotlin/com/infendro/mac/HMAC.kt b/src/commonMain/kotlin/com/infendro/mac/HMAC.kt index 922eef1..3e42e7d 100644 --- a/src/commonMain/kotlin/com/infendro/mac/HMAC.kt +++ b/src/commonMain/kotlin/com/infendro/mac/HMAC.kt @@ -22,11 +22,12 @@ class HMAC( function.hashInto(outer, destination, destinationOffset) } - private fun pad(key: ByteArray): ByteArray = - ByteArray(function.block).also { + private fun pad(key: ByteArray): ByteArray { + return ByteArray(function.block).also { when { key.size > function.block -> function.hashInto(key, it) else -> key.copyInto(it) } } + } } diff --git a/src/commonMain/kotlin/com/infendro/mac/MAC.kt b/src/commonMain/kotlin/com/infendro/mac/MAC.kt index 0069681..7d90d41 100644 --- a/src/commonMain/kotlin/com/infendro/mac/MAC.kt +++ b/src/commonMain/kotlin/com/infendro/mac/MAC.kt @@ -7,18 +7,9 @@ interface MAC { fun hashInto(key: ByteArray, value: ByteArray, destination: ByteArray, destinationOffset: Int = 0) - fun hashInto(key: ByteArray, value: ByteArray, destination: UByteArray, destinationOffset: Int = 0) = - hashInto(key, value, destination.asByteArray(), destinationOffset) - - fun hashInto(key: UByteArray, value: UByteArray, destination: ByteArray, destinationOffset: Int = 0) = - hashInto(key.asByteArray(), value.asByteArray(), destination, destinationOffset) - - fun hashInto(key: UByteArray, value: UByteArray, destination: UByteArray, destinationOffset: Int = 0) = - hashInto(key.asByteArray(), value.asByteArray(), destination.asByteArray(), destinationOffset) - - fun hash(key: ByteArray, value: ByteArray): ByteArray = - ByteArray(bytes).also { hashInto(key, value, it) } - - fun hash(key: UByteArray, value: UByteArray): UByteArray = - UByteArray(bytes).also { hashInto(key, value, it) } + fun hash(key: ByteArray, value: ByteArray): ByteArray { + val result = ByteArray(bytes) + hashInto(key, value, result) + return result + } } diff --git a/src/commonTest/kotlin/com/infendro/mac/HMAC.kt b/src/commonTest/kotlin/com/infendro/mac/HMAC.kt index 2964ec3..dec7dda 100644 --- a/src/commonTest/kotlin/com/infendro/mac/HMAC.kt +++ b/src/commonTest/kotlin/com/infendro/mac/HMAC.kt @@ -16,16 +16,12 @@ class `HMAC Test` { @Test fun example() { - val expected = ubyteArrayOf( - 0xf7U, 0xbcU, 0x83U, 0xf4U, - 0x30U, 0x53U, 0x84U, 0x24U, - 0xb1U, 0x32U, 0x98U, 0xe6U, - 0xaaU, 0x6fU, 0xb1U, 0x43U, - 0xefU, 0x4dU, 0x59U, 0xa1U, - 0x49U, 0x46U, 0x17U, 0x59U, - 0x97U, 0x47U, 0x9dU, 0xbcU, - 0x2dU, 0x1aU, 0x3cU, 0xd8U, - ).asByteArray() + val expected = byteArrayOf( + -0x09, -0x44, -0x7d, -0x0c, +0x30, +0x53, -0x7c, +0x24, + -0x4f, +0x32, -0x68, -0x1a, -0x56, +0x6f, -0x4f, +0x43, + -0x11, +0x4d, +0x59, -0x5f, +0x49, +0x46, +0x17, +0x59, + -0x69, +0x47, -0x63, -0x44, +0x2d, +0x1a, +0x3c, -0x28, + ) val actual = hmac.hash( "key".encodeToByteArray(), "The quick brown fox jumps over the lazy dog".encodeToByteArray(),