From 89e10eaff67d1b1583f7862e2c2af1da8cef4216 Mon Sep 17 00:00:00 2001 From: hfhbd Date: Tue, 31 Oct 2023 15:07:39 +0100 Subject: [PATCH 1/2] Fix timestamp prefix in UUIDv7 --- kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt index eecde96..be36623 100644 --- a/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt +++ b/kotlinx-uuid-core/src/commonMain/kotlin/kotlinx/uuid/UUID7.kt @@ -14,10 +14,10 @@ private const val UNIX_48_TIMESTAMP = 0x1FFF_FFFF_FFFF_FL @UUIDExperimentalAPI public fun UUIDv7(timeStamp: Long, random: Random = SecureRandom): UUID { require(timeStamp <= UNIX_48_TIMESTAMP) { - "timeStamp $timeStamp must be 48 bits, was $timeStamp." + "timeStamp $timeStamp must be <= 48 bits, was $timeStamp." } val leftTimeStamp = timeStamp shl 16 - val rand_a = (random.nextInt() shr 20).toLong() + val rand_a = random.nextBits(12).toLong() val timeStampAndVersionRaw = (leftTimeStamp or rand_a) and -0xf001L or 0x7000L // set variant to 4 or 5 From dcb2b08656f521c7836abd3f471dcb57f863f909 Mon Sep 17 00:00:00 2001 From: hfhbd Date: Tue, 31 Oct 2023 15:11:56 +0100 Subject: [PATCH 2/2] Fix timestamp prefix in UUIDv7 --- detekt-baseline.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/detekt-baseline.xml b/detekt-baseline.xml index 824050f..bfe607d 100644 --- a/detekt-baseline.xml +++ b/detekt-baseline.xml @@ -69,7 +69,6 @@ MagicNumber:UUID.kt$UUID$0x0fffL MagicNumber:UUID.kt$UUID$0x1fff MagicNumber:UUID.kt$UUID$0xf000L - MagicNumber:UUID.kt$UUID$0xffff00000000L MagicNumber:UUID.kt$UUID$0xffff0000L MagicNumber:UUID.kt$UUID$0xffffffffffffL MagicNumber:UUID.kt$UUID$12 @@ -90,9 +89,9 @@ MagicNumber:UUID7.kt$0x3fffffffffffffffL MagicNumber:UUID7.kt$0x7000L MagicNumber:UUID7.kt$0x80L + MagicNumber:UUID7.kt$12 MagicNumber:UUID7.kt$16 - MagicNumber:UUID7.kt$20 TooManyFunctions:SHA1.kt$SHA1 - VariableNaming:UUID7.kt$val rand_a = (random.nextInt() shr 20).toLong() + VariableNaming:UUID7.kt$val rand_a = random.nextBits(12).toLong()