Upgrade dependencies

This commit is contained in:
2026-03-12 11:25:47 +01:00
parent baf897e9e3
commit 8b0f24c6b4
3 changed files with 13 additions and 13 deletions

View File

@@ -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
}
}