Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
quuid_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2021 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QUUID_P_H
7#define QUUID_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists for the convenience
14// of the QLibrary class. This header file may change from
15// version to version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include "quuid.h"
21
22#include <QtCore/qrandom.h>
23
24#include <chrono>
25
26QT_BEGIN_NAMESPACE
27
28#ifndef QT_BOOTSTRAPPED
29static inline QUuid createUuidV7_internal(
30 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp)
31{
32 QUuid result;
33
34 using namespace std::chrono;
35 const nanoseconds nsecSinceEpoch = tp.time_since_epoch();
36 const auto msecSinceEpoch = floor<milliseconds>(nsecSinceEpoch);
37 const quint64 frac = (nsecSinceEpoch - msecSinceEpoch).count();
38 // Lower 48 bits of the timestamp
39 const quint64 msecs = quint64(msecSinceEpoch.count()) & 0xffffffffffff;
40 result.data1 = uint(msecs >> 16);
41 result.data2 = ushort(msecs);
42 // rand_a: use a 12-bit sub-millisecond timestamp for additional monotonicity
43 // https://datatracker.ietf.org/doc/html/rfc9562#monotonicity_counters (Method 3)
44
45 // "frac" is a number between 0 and 999,999, so the lowest 20 bits
46 // should be roughly random. Use the high 12 of those for additional
47 // monotonicity.
48 result.data3 = frac >> 8;
49 result.data3 &= 0x0FFF;
50 result.data3 |= ushort(7) << 12;
51
52 // rand_b: 62 bits of random data (64 - 2 bits for the variant)
53 const quint64 random = QRandomGenerator::system()->generate64();
54 memcpy(result.data4, &random, sizeof(quint64));
55 result.data4[0] = (result.data4[0] & 0x3F) | 0x80; // UV_DCE
56 return result;
57}
58#endif
59
60QT_END_NAMESPACE
61
62#endif // QUUID_P_H
Combined button and popup list for selecting options.
QDataStream & operator>>(QDataStream &s, QKeyCombination &combination)
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:192
bool _q_fromHex(const char *&src, Integral &value)
Definition quuid.cpp:42
static char * _q_uuidToHex(const QUuid &uuid, char *dst, QUuid::StringFormat mode=QUuid::WithBraces)
Definition quuid.cpp:58
void _q_toHex(char *&dst, Integral value)
Definition quuid.cpp:26
@ MaxStringUuidLength
Definition quuid.cpp:23
static QUuid uuidFromString(QStringView text) noexcept
Definition quuid.cpp:499
static QUuid createFromName(QUuid ns, QByteArrayView baseData, QCryptographicHash::Algorithm algorithm, int version) noexcept
Definition quuid.cpp:124