From 4ced19be57d45a393a4560ef4ae1c1390c4152af Mon Sep 17 00:00:00 2001 From: Sander Dijkhuis Date: Wed, 31 Jan 2024 17:00:37 +0100 Subject: [PATCH] fix: never reach reserved maximum nonce --- src/main/kotlin/cryptography/Nonce.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/cryptography/Nonce.kt b/src/main/kotlin/cryptography/Nonce.kt index f055292..b77b9f5 100644 --- a/src/main/kotlin/cryptography/Nonce.kt +++ b/src/main/kotlin/cryptography/Nonce.kt @@ -9,7 +9,7 @@ value class Nonce(val value: ULong) { val bytes: ByteArray get() = SIZE.byteArray { (value shr (it * Byte.SIZE_BITS)).toByte() } - fun increment(): Nonce? = if (value == ULong.MAX_VALUE) null else Nonce(value + 1uL) + fun increment(): Nonce? = if (value >= ULong.MAX_VALUE - 2uL) null else Nonce(value + 1uL) companion object {