From 8b0f24c6b4ea0bd0011572fd6b35d353c65e367c Mon Sep 17 00:00:00 2001 From: Infendro Date: Thu, 12 Mar 2026 11:25:47 +0100 Subject: [PATCH] Upgrade dependencies --- gradle/libs.versions.toml | 6 +++--- src/commonMain/kotlin/com/infendro/otp/HOTP.kt | 10 +++++----- src/commonMain/kotlin/com/infendro/otp/TOTP.kt | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4215199..07641bb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,9 +1,9 @@ [versions] infendro = "1.1.0" kotlin = "2.3.0" -bytes = "1.4.0" -hash = "1.6.0" -mac = "1.4.0" +bytes = "1.4.2" +hash = "1.7.0" +mac = "1.5.0" [plugins] infendro = { id = "com.infendro.plugin", version.ref = "infendro" } diff --git a/src/commonMain/kotlin/com/infendro/otp/HOTP.kt b/src/commonMain/kotlin/com/infendro/otp/HOTP.kt index 687e694..429ee48 100644 --- a/src/commonMain/kotlin/com/infendro/otp/HOTP.kt +++ b/src/commonMain/kotlin/com/infendro/otp/HOTP.kt @@ -9,7 +9,7 @@ import com.infendro.otp.util.pow import kotlin.experimental.and class HOTP( - val function: HashFunction = SHA1, + val function: HashFunction = SHA1(), val length: Int = 6, ) { private val hmac = HMAC(function) @@ -19,14 +19,14 @@ class HOTP( return otp(secret, counter) } + fun verify(secret: ByteArray, counter: Long, otp: String): Boolean { + return generate(secret, counter) == otp + } + private fun otp(secret: ByteArray, counter: Long): String { val hash = hmac.hash(secret, counter.toByteArray()) val offset = (hash.last() and 0xF).toInt() val otp = (hash.toInt(offset) and 0x7FFFFFFF) % 10.pow(length) return "$otp".padStart(length, '0') } - - fun verify(secret: ByteArray, counter: Long, otp: String): Boolean { - return generate(secret, counter) == otp - } } diff --git a/src/commonMain/kotlin/com/infendro/otp/TOTP.kt b/src/commonMain/kotlin/com/infendro/otp/TOTP.kt index 1312534..14912ae 100644 --- a/src/commonMain/kotlin/com/infendro/otp/TOTP.kt +++ b/src/commonMain/kotlin/com/infendro/otp/TOTP.kt @@ -7,7 +7,7 @@ import kotlin.time.Duration.Companion.seconds import kotlin.time.Instant class TOTP( - val function: HashFunction = SHA1, + val function: HashFunction = SHA1(), val length: Int = 6, val period: Duration = 30.seconds, ) { @@ -17,13 +17,13 @@ class TOTP( return hotp.generate(secret, counter(instant)) } + fun verify(secret: ByteArray, instant: Instant, otp: String): Boolean { + return generate(secret, instant) == otp + } + private fun counter(instant: Instant): Long { val ms = instant.toEpochMilliseconds() val d = period.inWholeMilliseconds return ms / d } - - fun verify(secret: ByteArray, instant: Instant, otp: String): Boolean { - return generate(secret, instant) == otp - } }