Skip to content

Commit

Permalink
fix: never reach reserved maximum nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
sander committed Jan 31, 2024
1 parent a309727 commit f057fb0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/kotlin/cryptography/Nonce.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 - 1uL) null else Nonce(value + 1uL)

companion object {

Expand Down

0 comments on commit f057fb0

Please sign in to comment.