QUuid: port fromRfc4122() to QByteArrayView
Remove the QByteArray overload from the API, but not the ABI. Adapt callers. Change-Id: I88aa09cbca3b89d0b249ce336ebe49c4b352c9e1 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
3a72496b5c
commit
767e00a2d7
@ -57,6 +57,13 @@ QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method)
|
|||||||
return hash(QByteArrayView{data}, method);
|
return hash(QByteArrayView{data}, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "quuid.h"
|
||||||
|
|
||||||
|
QUuid QUuid::fromRfc4122(const QByteArray &bytes)
|
||||||
|
{
|
||||||
|
return fromRfc4122(qToByteArrayViewIgnoringNull(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
// #include <qotherheader.h>
|
// #include <qotherheader.h>
|
||||||
// // implement removed functions from qotherheader.h
|
// // implement removed functions from qotherheader.h
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ QUuid QUuid::fromCFUUID(CFUUIDRef uuid)
|
|||||||
if (!uuid)
|
if (!uuid)
|
||||||
return QUuid();
|
return QUuid();
|
||||||
const CFUUIDBytes bytes = CFUUIDGetUUIDBytes(uuid);
|
const CFUUIDBytes bytes = CFUUIDGetUUIDBytes(uuid);
|
||||||
return QUuid::fromRfc4122(QByteArray::fromRawData(reinterpret_cast<const char *>(&bytes), sizeof(bytes)));
|
return QUuid::fromRfc4122(QByteArrayView(reinterpret_cast<const char *>(&bytes), sizeof(bytes)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -354,7 +354,7 @@ QUuid QUuid::fromNSUUID(const NSUUID *uuid)
|
|||||||
return QUuid();
|
return QUuid();
|
||||||
uuid_t bytes;
|
uuid_t bytes;
|
||||||
[uuid getUUIDBytes:bytes];
|
[uuid getUUIDBytes:bytes];
|
||||||
return QUuid::fromRfc4122(QByteArray::fromRawData(reinterpret_cast<const char *>(bytes), sizeof(bytes)));
|
return QUuid::fromRfc4122(QByteArrayView(reinterpret_cast<const char *>(bytes), sizeof(bytes)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -151,16 +151,12 @@ static QUuid _q_uuidFromHex(const char *src)
|
|||||||
|
|
||||||
static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version)
|
static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCryptographicHash::Algorithm algorithm, int version)
|
||||||
{
|
{
|
||||||
QByteArray hashResult;
|
QCryptographicHash hash(algorithm);
|
||||||
|
hash.addData(ns.toRfc4122());
|
||||||
// create a scope so later resize won't reallocate
|
hash.addData(baseData);
|
||||||
{
|
QByteArrayView hashResult = hash.resultView();
|
||||||
QCryptographicHash hash(algorithm);
|
Q_ASSERT(hashResult.size() >= 16);
|
||||||
hash.addData(ns.toRfc4122());
|
hashResult.truncate(16); // Sha1 will be too long
|
||||||
hash.addData(baseData);
|
|
||||||
hashResult = hash.result();
|
|
||||||
}
|
|
||||||
hashResult.resize(16); // Sha1 will be too long
|
|
||||||
|
|
||||||
QUuid result = QUuid::fromRfc4122(hashResult);
|
QUuid result = QUuid::fromRfc4122(hashResult);
|
||||||
|
|
||||||
@ -524,20 +520,23 @@ QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData)
|
|||||||
|
|
||||||
If the conversion fails, a null UUID is created.
|
If the conversion fails, a null UUID is created.
|
||||||
|
|
||||||
|
\note In Qt versions prior to 6.3, this function took QByteArray, not
|
||||||
|
QByteArrayView.
|
||||||
|
|
||||||
\since 4.8
|
\since 4.8
|
||||||
|
|
||||||
\sa toRfc4122(), QUuid()
|
\sa toRfc4122(), QUuid()
|
||||||
*/
|
*/
|
||||||
QUuid QUuid::fromRfc4122(const QByteArray &bytes)
|
QUuid QUuid::fromRfc4122(QByteArrayView bytes) noexcept
|
||||||
{
|
{
|
||||||
if (bytes.isEmpty() || bytes.length() != 16)
|
if (bytes.isEmpty() || bytes.size() != 16)
|
||||||
return QUuid();
|
return QUuid();
|
||||||
|
|
||||||
uint d1;
|
uint d1;
|
||||||
ushort d2, d3;
|
ushort d2, d3;
|
||||||
uchar d4[8];
|
uchar d4[8];
|
||||||
|
|
||||||
const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
|
const uchar *data = reinterpret_cast<const uchar *>(bytes.data());
|
||||||
|
|
||||||
d1 = qFromBigEndian<quint32>(data);
|
d1 = qFromBigEndian<quint32>(data);
|
||||||
data += sizeof(quint32);
|
data += sizeof(quint32);
|
||||||
@ -744,7 +743,7 @@ QDataStream &operator<<(QDataStream &s, const QUuid &id)
|
|||||||
*/
|
*/
|
||||||
QDataStream &operator>>(QDataStream &s, QUuid &id)
|
QDataStream &operator>>(QDataStream &s, QUuid &id)
|
||||||
{
|
{
|
||||||
QByteArray bytes(16, Qt::Uninitialized);
|
std::array<char, 16> bytes;
|
||||||
if (s.readRawData(bytes.data(), 16) != 16) {
|
if (s.readRawData(bytes.data(), 16) != 16) {
|
||||||
s.setStatus(QDataStream::ReadPastEnd);
|
s.setStatus(QDataStream::ReadPastEnd);
|
||||||
return s;
|
return s;
|
||||||
@ -753,7 +752,7 @@ QDataStream &operator>>(QDataStream &s, QUuid &id)
|
|||||||
if (s.byteOrder() == QDataStream::BigEndian) {
|
if (s.byteOrder() == QDataStream::BigEndian) {
|
||||||
id = QUuid::fromRfc4122(bytes);
|
id = QUuid::fromRfc4122(bytes);
|
||||||
} else {
|
} else {
|
||||||
const uchar *data = reinterpret_cast<const uchar *>(bytes.constData());
|
const uchar *data = reinterpret_cast<const uchar *>(bytes.data());
|
||||||
|
|
||||||
id.data1 = qFromLittleEndian<quint32>(data);
|
id.data1 = qFromLittleEndian<quint32>(data);
|
||||||
data += sizeof(quint32);
|
data += sizeof(quint32);
|
||||||
|
@ -105,7 +105,10 @@ public:
|
|||||||
explicit QUuid(const QByteArray &);
|
explicit QUuid(const QByteArray &);
|
||||||
QByteArray toByteArray(StringFormat mode = WithBraces) const;
|
QByteArray toByteArray(StringFormat mode = WithBraces) const;
|
||||||
QByteArray toRfc4122() const;
|
QByteArray toRfc4122() const;
|
||||||
|
#if QT_REMOVED_SINCE(6, 3)
|
||||||
static QUuid fromRfc4122(const QByteArray &);
|
static QUuid fromRfc4122(const QByteArray &);
|
||||||
|
#endif
|
||||||
|
static QUuid fromRfc4122(QByteArrayView) noexcept;
|
||||||
bool isNull() const noexcept;
|
bool isNull() const noexcept;
|
||||||
|
|
||||||
constexpr bool operator==(const QUuid &orig) const noexcept
|
constexpr bool operator==(const QUuid &orig) const noexcept
|
||||||
|
Loading…
Reference in New Issue
Block a user