summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/quuid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/plugin/quuid.cpp')
-rw-r--r--src/corelib/plugin/quuid.cpp65
1 files changed, 63 insertions, 2 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index 46589f88bc..e73508fce6 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -133,6 +133,29 @@ bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar (&
}
#endif
+static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version)
+{
+ QByteArray hashResult;
+
+ // create a scope so later resize won't reallocate
+ {
+ QCryptographicHash hash(algorithm);
+ hash.addData(ns.toRfc4122());
+ hash.addData(baseData);
+ hashResult = hash.result();
+ }
+ hashResult.resize(16); // Sha1 will be too long
+
+ QUuid result = QUuid::fromRfc4122(hashResult);
+
+ result.data3 &= 0x0FFF;
+ result.data3 |= (version << 12);
+ result.data4[0] &= 0x3F;
+ result.data4[0] |= 0x80;
+
+ return result;
+}
+
/*!
\class QUuid
\brief The QUuid class stores a Universally Unique Identifier (UUID).
@@ -231,7 +254,7 @@ bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar (&
\o 0
\o 1
\o 1
- \o Name
+ \o Md5(Name)
\row
\o 0
@@ -240,6 +263,13 @@ bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar (&
\o 0
\o Random
+ \row
+ \o 0
+ \o 1
+ \o 0
+ \o 1
+ \o Sha1
+
\endtable
The field layouts for the DCE versions listed in the table above
@@ -385,9 +415,40 @@ QUuid::QUuid(const QByteArray &text)
return;
}
}
+
#endif
/*!
+ \since 5.0
+ \fn QUuid::createUuidV3()
+
+ This functions returns a new UUID with variant QUuid::DCE and version QUuid::MD5.
+ \a ns is the namespace and \a name is the name as described by RFC 4122.
+
+ \sa variant(), version(), createUuidV5()
+*/
+
+/*!
+ \since 5.0
+ \fn QUuid::createUuidV5()
+
+ This functions returns a new UUID with variant QUuid::DCE and version QUuid::SHA1.
+ \a ns is the namespace and \a name is the name as described by RFC 4122.
+
+ \sa variant(), version(), createUuidV3()
+*/
+
+QUuid QUuid::createUuidV3(const QUuid &ns, const QByteArray &baseData)
+{
+ return createFromName(ns, baseData, QCryptographicHash::Md5, 3);
+}
+
+QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData)
+{
+ return createFromName(ns, baseData, QCryptographicHash::Sha1, 5);
+}
+
+/*!
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 bytes required.
@@ -731,7 +792,7 @@ QUuid::Version QUuid::version() const
if (isNull()
|| (variant() != DCE)
|| ver < Time
- || ver > Random)
+ || ver > Sha1)
return VerUnknown;
return ver;
}