minor refactor
All checks were successful
/ test (pull_request) Successful in 33s

This commit is contained in:
2026-01-30 13:23:32 +01:00
parent 59f7d925a3
commit f5f073168d
2 changed files with 8 additions and 8 deletions

View File

@@ -14,10 +14,6 @@ class HOTP(
) {
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 {
require(counter >= 0)
return otp(secret, counter)
@@ -29,4 +25,8 @@ class HOTP(
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
}
}

View File

@@ -13,10 +13,6 @@ class TOTP(
) {
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 {
return hotp.generate(secret, counter(instant))
}
@@ -26,4 +22,8 @@ class TOTP(
val d = period.inWholeMilliseconds
return ms / d
}
fun verify(secret: ByteArray, instant: Instant, otp: String): Boolean {
return generate(secret, instant) == otp
}
}