1.3.0 release #2

Merged
Infendro merged 7 commits from develop into main 2026-02-16 18:21:00 +00:00
2 changed files with 8 additions and 8 deletions
Showing only changes of commit f5f073168d - Show all commits

View File

@@ -14,10 +14,6 @@ class HOTP(
) { ) {
private val hmac = HMAC(function) private val hmac = HMAC(function)
fun verify(secret: ByteArray, counter: Long, otp: String): Boolean {
return generate(secret, counter) == otp
}
fun generate(secret: ByteArray, counter: Long): String { fun generate(secret: ByteArray, counter: Long): String {
require(counter >= 0) require(counter >= 0)
return otp(secret, counter) return otp(secret, counter)
@@ -29,4 +25,8 @@ class HOTP(
val otp = (hash.toInt(offset) and 0x7FFFFFFF) % 10.pow(length) val otp = (hash.toInt(offset) and 0x7FFFFFFF) % 10.pow(length)
return "$otp".padStart(length, '0') return "$otp".padStart(length, '0')
} }
fun verify(secret: ByteArray, counter: Long, otp: String): Boolean {
return generate(secret, counter) == otp
}
} }

View File

@@ -13,10 +13,6 @@ class TOTP(
) { ) {
private val hotp = HOTP(function, length) private val hotp = HOTP(function, length)
fun verify(secret: ByteArray, instant: Instant, otp: String): Boolean {
return generate(secret, instant) == otp
}
fun generate(secret: ByteArray, instant: Instant): String { fun generate(secret: ByteArray, instant: Instant): String {
return hotp.generate(secret, counter(instant)) return hotp.generate(secret, counter(instant))
} }
@@ -26,4 +22,8 @@ class TOTP(
val d = period.inWholeMilliseconds val d = period.inWholeMilliseconds
return ms / d return ms / d
} }
fun verify(secret: ByteArray, instant: Instant, otp: String): Boolean {
return generate(secret, instant) == otp
}
} }