summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/quuid.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2024-11-29 18:29:16 +0200
committerAhmad Samir <a.samirh78@gmail.com>2024-12-07 17:30:37 +0200
commitd89cef439f5c1a58aeff879a12d9a33292764b7f (patch)
tree89665b375ecbaa90c85be188240ba8f2dd479043 /src/corelib/plugin/quuid.cpp
parent84a5f50c7766c99f62b22bb4388137e0aa8dd13d (diff)
QUuid: add support for creating UUID v7
Thanks to Thiago for the more efficient way of using 12 bits of the sub-milliseconds part of the timestamp. Previously I used the method described in the RFC (value of type double multiplied by 4096). Add a private helper to check the version since now there is a gap in the Version enum values (UUID v6 isn't supported). Drive-by, document Version::Sha1 enumerator. [ChangeLog][QtCore][QUuid] Added support for creating UUID v7 as described in https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-7 Fixes: QTBUG-130672 Change-Id: Idfea9fbb12a7f28e25b27b56a3b402799afb4864 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/plugin/quuid.cpp')
-rw-r--r--src/corelib/plugin/quuid.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index 0b1615c6499..e0d621dec80 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "quuid.h"
+#include "quuid_p.h"
#include "qcryptographichash.h"
#include "qdatastream.h"
@@ -543,7 +544,7 @@ QUuid QUuid::fromString(QAnyStringView text) noexcept
\note In Qt versions prior to 6.8, this function took QByteArray, not
QByteArrayView.
- \sa variant(), version(), createUuidV5()
+ \sa variant(), version(), createUuidV5(), createUuidV7()
*/
/*!
@@ -553,7 +554,7 @@ QUuid QUuid::fromString(QAnyStringView text) noexcept
This function returns a new UUID with variant QUuid::DCE and version QUuid::Md5.
\a ns is the namespace and \a baseData is the basic data as described by RFC 4122.
- \sa variant(), version(), createUuidV5()
+ \sa variant(), version(), createUuidV5(), createUuidV7()
*/
/*!
@@ -591,6 +592,25 @@ QUuid QUuid::createUuidV5(QUuid ns, QByteArrayView baseData) noexcept
}
/*!
+ \since 6.9
+
+ This function returns a new UUID with variant QUuid::DCE and version
+ QUuid::UnixEpoch.
+
+ It uses a time-ordered value field derived from the number of milliseconds
+ since the UNIX Epoch as described by
+ \l {https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-7}{RFC9562}.
+
+ \sa variant(), version(), createUuidV3(), createUuidV5()
+*/
+#ifndef QT_BOOTSTRAPPED
+QUuid QUuid::createUuidV7()
+{
+ return createUuidV7_internal(std::chrono::system_clock::now());
+}
+#endif // !defined(QT_BOOTSTRAPPED)
+
+/*!
Creates a QUuid object from the binary representation of the UUID, as
specified by RFC 4122 section 4.1.2. See toRfc4122() for a further
explanation of the order of \a bytes required.
@@ -861,7 +881,9 @@ QDataStream &operator>>(QDataStream &s, QUuid &id)
\value Name Name-based, by using values from a name for all sections
\value Md5 Alias for Name
\value Random Random-based, by using random numbers for all sections
- \value Sha1
+ \value Sha1 Name-based version that uses SHA-1 hashing
+ \value UnixEpoch Time-based UUID using the number of milliseconds since
+ the UNIX epoch
*/
/*!