From ba1c9830949381894f95ef5b056fd1e58121eee7 Mon Sep 17 00:00:00 2001 From: Infendro Date: Thu, 24 Jul 2025 21:07:32 +0200 Subject: [PATCH] update dependencies --- build.gradle.kts | 4 +++- gradle/libs.versions.toml | 10 +++++++--- .../kotlin/com/infendro/otp/HOTP.kt | 7 +++---- .../com/infendro/otp/SecretGenerator.kt | 4 ++-- .../kotlin/com/infendro/otp/util/ByteArray.kt | 20 ------------------- 5 files changed, 15 insertions(+), 30 deletions(-) delete mode 100644 src/commonMain/kotlin/com/infendro/otp/util/ByteArray.kt diff --git a/build.gradle.kts b/build.gradle.kts index 707ae10..4df0599 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,8 +20,10 @@ kotlin { sourceSets { commonMain.dependencies { - implementation(libs.hash) + implementation(libs.random) implementation(libs.mac) + implementation(libs.hash) + implementation(libs.bytearray) } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9abbcfd..87727d7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,11 +1,15 @@ [versions] kotlin = "2.1.20" -hash = "1.1.0" -mac = "1.1.0" +random = "1.0.0" +mac = "1.1.2" +hash = "1.2.2" +bytearray = "1.1.1" [plugins] multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } [libraries] -hash = { module = "com.infendro:hash", version.ref = "hash" } +random = { module = "com.infendro:random", version.ref = "random" } mac = { module = "com.infendro:mac", version.ref = "mac" } +hash = { module = "com.infendro:hash", version.ref = "hash" } +bytearray = { module = "com.infendro:bytearray", version.ref = "bytearray" } diff --git a/src/commonMain/kotlin/com/infendro/otp/HOTP.kt b/src/commonMain/kotlin/com/infendro/otp/HOTP.kt index e9a3950..28d6b37 100644 --- a/src/commonMain/kotlin/com/infendro/otp/HOTP.kt +++ b/src/commonMain/kotlin/com/infendro/otp/HOTP.kt @@ -1,10 +1,10 @@ package com.infendro.otp +import com.infendro.bytearray.toByteArray +import com.infendro.bytearray.toInt import com.infendro.hash.HashFunction import com.infendro.hash.SHA1 import com.infendro.mac.HMAC -import com.infendro.otp.util.toByteArray -import com.infendro.otp.util.toInt import kotlin.experimental.and import kotlin.math.pow @@ -24,8 +24,7 @@ class HOTP( secret: ByteArray, counter: Long, ): String { - if (counter < 0) - throw Exception() + if (counter < 0) throw Exception() val hash = generateHash( secret, diff --git a/src/commonMain/kotlin/com/infendro/otp/SecretGenerator.kt b/src/commonMain/kotlin/com/infendro/otp/SecretGenerator.kt index 19f5033..a1ee623 100644 --- a/src/commonMain/kotlin/com/infendro/otp/SecretGenerator.kt +++ b/src/commonMain/kotlin/com/infendro/otp/SecretGenerator.kt @@ -1,10 +1,10 @@ package com.infendro.otp import com.infendro.hash.* -import kotlin.random.Random +import com.infendro.random.PRNG object SecretGenerator { - private val random = Random.Default + private val random = PRNG.HMAC fun generate( algorithm: HashFunction = SHA1, diff --git a/src/commonMain/kotlin/com/infendro/otp/util/ByteArray.kt b/src/commonMain/kotlin/com/infendro/otp/util/ByteArray.kt deleted file mode 100644 index d45fd16..0000000 --- a/src/commonMain/kotlin/com/infendro/otp/util/ByteArray.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.infendro.otp.util - -internal fun Long.toByteArray(): ByteArray { - return ByteArray(8) { i -> - val offset = (7 - i) * 8 - (this shr offset).toByte() - } -} - -internal fun ByteArray.toInt(): Int { - if (size != 4) throw Exception() - - return fold(0) { acc, byte -> - (acc shl 8) or (byte.toInt() and 0xFF) - } -} - -internal fun Collection.toInt(): Int { - return toByteArray().toInt() -}