Skip to content

Commit 4ced19b

Browse files
committed
fix: never reach reserved maximum nonce
1 parent a309727 commit 4ced19b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/kotlin/cryptography/Nonce.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ value class Nonce(val value: ULong) {
99

1010
val bytes: ByteArray get() = SIZE.byteArray { (value shr (it * Byte.SIZE_BITS)).toByte() }
1111

12-
fun increment(): Nonce? = if (value == ULong.MAX_VALUE) null else Nonce(value + 1uL)
12+
fun increment(): Nonce? = if (value >= ULong.MAX_VALUE - 2uL) null else Nonce(value + 1uL)
1313

1414
companion object {
1515

0 commit comments

Comments
 (0)