Merge pull request #1770 from pasdam/feature/useQuuid

Replaced Uuid with QUuid
This commit is contained in:
Jonathan White 2018-07-08 20:32:54 -04:00 committed by GitHub
commit 470a74ee24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 438 additions and 645 deletions

View File

@ -66,7 +66,6 @@ set(keepassx_SOURCES
core/TimeInfo.cpp core/TimeInfo.cpp
core/Tools.cpp core/Tools.cpp
core/Translator.cpp core/Translator.cpp
core/Uuid.cpp
core/Base32.h core/Base32.h
core/Base32.cpp core/Base32.cpp
cli/Utils.cpp cli/Utils.cpp

View File

@ -17,6 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QJsonArray>
#include <QInputDialog>
#include <QProgressDialog>
#include <QMessageBox>
#include <QUuid>
#include "BrowserService.h" #include "BrowserService.h"
#include "BrowserAccessControlDialog.h" #include "BrowserAccessControlDialog.h"
#include "BrowserEntryConfig.h" #include "BrowserEntryConfig.h"
@ -26,19 +32,9 @@
#include "core/Group.h" #include "core/Group.h"
#include "core/Metadata.h" #include "core/Metadata.h"
#include "core/PasswordGenerator.h" #include "core/PasswordGenerator.h"
#include "core/Uuid.h"
#include "gui/MainWindow.h" #include "gui/MainWindow.h"
#include <QInputDialog>
#include <QJsonArray>
#include <QMessageBox>
#include <QProgressDialog>
// de887cc3-0363-43b8-974b-5911b8816224 static const QUuid KEEPASSXCBROWSER_UUID = QUuid::fromRfc4122(QByteArray::fromHex("de887cc3036343b8974b5911b8816224"));
static const unsigned char KEEPASSXCBROWSER_UUID_DATA[] =
{0xde, 0x88, 0x7c, 0xc3, 0x03, 0x63, 0x43, 0xb8, 0x97, 0x4b, 0x59, 0x11, 0xb8, 0x81, 0x62, 0x24};
static const Uuid KEEPASSXCBROWSER_UUID =
Uuid(QByteArray::fromRawData(reinterpret_cast<const char*>(KEEPASSXCBROWSER_UUID_DATA),
sizeof(KEEPASSXCBROWSER_UUID_DATA)));
static const char KEEPASSXCBROWSER_NAME[] = "KeePassXC-Browser Settings"; static const char KEEPASSXCBROWSER_NAME[] = "KeePassXC-Browser Settings";
static const char ASSOCIATE_KEY_PREFIX[] = "Public Key: "; static const char ASSOCIATE_KEY_PREFIX[] = "Public Key: ";
static const char KEEPASSXCBROWSER_GROUP_NAME[] = "KeePassXC-Browser Passwords"; static const char KEEPASSXCBROWSER_GROUP_NAME[] = "KeePassXC-Browser Passwords";
@ -118,7 +114,7 @@ QString BrowserService::getDatabaseRootUuid()
return QString(); return QString();
} }
return rootGroup->uuid().toHex(); return QString::fromLatin1(rootGroup->uuid().toRfc4122().toHex());
} }
QString BrowserService::getDatabaseRecycleBinUuid() QString BrowserService::getDatabaseRecycleBinUuid()
@ -132,7 +128,7 @@ QString BrowserService::getDatabaseRecycleBinUuid()
if (!recycleBin) { if (!recycleBin) {
return QString(); return QString();
} }
return recycleBin->uuid().toHex(); return QString::fromLatin1(recycleBin->uuid().toRfc4122().toHex());
} }
Entry* BrowserService::getConfigEntry(bool create) Entry* BrowserService::getConfigEntry(bool create)
@ -306,7 +302,7 @@ void BrowserService::addEntry(const QString&,
} }
Entry* entry = new Entry(); Entry* entry = new Entry();
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
entry->setTitle(QUrl(url).host()); entry->setTitle(QUrl(url).host());
entry->setUrl(url); entry->setUrl(url);
entry->setIcon(KEEPASSXCBROWSER_DEFAULT_ICON); entry->setIcon(KEEPASSXCBROWSER_DEFAULT_ICON);
@ -350,7 +346,7 @@ void BrowserService::updateEntry(const QString& id,
return; return;
} }
Entry* entry = db->resolveEntry(Uuid::fromHex(uuid)); Entry* entry = db->resolveEntry(QUuid::fromRfc4122(QByteArray::fromHex(uuid.toLatin1())));
if (!entry) { if (!entry) {
return; return;
} }
@ -631,7 +627,7 @@ QJsonObject BrowserService::prepareEntry(const Entry* entry)
res["login"] = entry->resolveMultiplePlaceholders(entry->username()); res["login"] = entry->resolveMultiplePlaceholders(entry->username());
res["password"] = entry->resolveMultiplePlaceholders(entry->password()); res["password"] = entry->resolveMultiplePlaceholders(entry->password());
res["name"] = entry->resolveMultiplePlaceholders(entry->title()); res["name"] = entry->resolveMultiplePlaceholders(entry->title());
res["uuid"] = entry->resolveMultiplePlaceholders(entry->uuid().toHex()); res["uuid"] = entry->resolveMultiplePlaceholders(QString::fromLatin1(entry->uuid().toRfc4122().toHex()));
if (entry->hasTotp()) { if (entry->hasTotp()) {
res["totp"] = entry->totp(); res["totp"] = entry->totp();
@ -693,7 +689,7 @@ Group* BrowserService::findCreateAddEntryGroup()
} }
Group* group = new Group(); Group* group = new Group();
group->setUuid(Uuid::random()); group->setUuid(QUuid::createUuid());
group->setName(groupName); group->setName(groupName);
group->setIcon(KEEPASSXCBROWSER_DEFAULT_ICON); group->setIcon(KEEPASSXCBROWSER_DEFAULT_ICON);
group->setParent(rootGroup); group->setParent(rootGroup);

View File

@ -18,6 +18,7 @@
#include "Database.h" #include "Database.h"
#include <QDebug>
#include <QFile> #include <QFile>
#include <QSaveFile> #include <QSaveFile>
#include <QTemporaryFile> #include <QTemporaryFile>
@ -35,13 +36,13 @@
#include "keys/FileKey.h" #include "keys/FileKey.h"
#include "keys/PasswordKey.h" #include "keys/PasswordKey.h"
QHash<Uuid, Database*> Database::m_uuidMap; QHash<QUuid, Database*> Database::m_uuidMap;
Database::Database() Database::Database()
: m_metadata(new Metadata(this)) : m_metadata(new Metadata(this))
, m_timer(new QTimer(this)) , m_timer(new QTimer(this))
, m_emitModified(false) , m_emitModified(false)
, m_uuid(Uuid::random()) , m_uuid(QUuid::createUuid())
{ {
m_data.cipher = KeePass2::CIPHER_AES; m_data.cipher = KeePass2::CIPHER_AES;
m_data.compressionAlgo = CompressionGZip; m_data.compressionAlgo = CompressionGZip;
@ -53,7 +54,7 @@ Database::Database()
m_data.hasKey = false; m_data.hasKey = false;
setRootGroup(new Group()); setRootGroup(new Group());
rootGroup()->setUuid(Uuid::random()); rootGroup()->setUuid(QUuid::createUuid());
m_timer->setSingleShot(true); m_timer->setSingleShot(true);
m_uuidMap.insert(m_uuid, this); m_uuidMap.insert(m_uuid, this);
@ -97,7 +98,7 @@ const Metadata* Database::metadata() const
return m_metadata; return m_metadata;
} }
Entry* Database::resolveEntry(const Uuid& uuid) Entry* Database::resolveEntry(const QUuid& uuid)
{ {
return findEntryRecursive(uuid, m_rootGroup); return findEntryRecursive(uuid, m_rootGroup);
} }
@ -107,7 +108,7 @@ Entry* Database::resolveEntry(const QString& text, EntryReferenceType referenceT
return findEntryRecursive(text, referenceType, m_rootGroup); return findEntryRecursive(text, referenceType, m_rootGroup);
} }
Entry* Database::findEntryRecursive(const Uuid& uuid, Group* group) Entry* Database::findEntryRecursive(const QUuid& uuid, Group* group)
{ {
const QList<Entry*> entryList = group->entries(); const QList<Entry*> entryList = group->entries();
for (Entry* entry : entryList) { for (Entry* entry : entryList) {
@ -154,8 +155,8 @@ Entry* Database::findEntryRecursive(const QString& text, EntryReferenceType refe
case EntryReferenceType::Notes: case EntryReferenceType::Notes:
found = entry->notes() == text; found = entry->notes() == text;
break; break;
case EntryReferenceType::Uuid: case EntryReferenceType::QUuid:
found = entry->uuid() == Uuid::fromHex(text); found = entry->uuid() == QUuid::fromRfc4122(QByteArray::fromHex(text.toLatin1()));
break; break;
case EntryReferenceType::CustomAttributes: case EntryReferenceType::CustomAttributes:
found = entry->attributes()->containsValue(text); found = entry->attributes()->containsValue(text);
@ -178,12 +179,12 @@ Entry* Database::findEntryRecursive(const QString& text, EntryReferenceType refe
return nullptr; return nullptr;
} }
Group* Database::resolveGroup(const Uuid& uuid) Group* Database::resolveGroup(const QUuid& uuid)
{ {
return findGroupRecursive(uuid, m_rootGroup); return findGroupRecursive(uuid, m_rootGroup);
} }
Group* Database::findGroupRecursive(const Uuid& uuid, Group* group) Group* Database::findGroupRecursive(const QUuid& uuid, Group* group)
{ {
if (group->uuid() == uuid) { if (group->uuid() == uuid) {
return group; return group;
@ -211,7 +212,7 @@ void Database::addDeletedObject(const DeletedObject& delObj)
m_deletedObjects.append(delObj); m_deletedObjects.append(delObj);
} }
void Database::addDeletedObject(const Uuid& uuid) void Database::addDeletedObject(const QUuid& uuid)
{ {
DeletedObject delObj; DeletedObject delObj;
delObj.deletionTime = QDateTime::currentDateTimeUtc(); delObj.deletionTime = QDateTime::currentDateTimeUtc();
@ -220,7 +221,7 @@ void Database::addDeletedObject(const Uuid& uuid)
addDeletedObject(delObj); addDeletedObject(delObj);
} }
Uuid Database::cipher() const const QUuid& Database::cipher() const
{ {
return m_data.cipher; return m_data.cipher;
} }
@ -246,7 +247,7 @@ bool Database::challengeMasterSeed(const QByteArray& masterSeed)
return m_data.key.challenge(masterSeed, m_data.challengeResponseKey); return m_data.key.challenge(masterSeed, m_data.challengeResponseKey);
} }
void Database::setCipher(const Uuid& cipher) void Database::setCipher(const QUuid& cipher)
{ {
Q_ASSERT(!cipher.isNull()); Q_ASSERT(!cipher.isNull());
@ -387,10 +388,10 @@ void Database::merge(const Database* other)
{ {
m_rootGroup->merge(other->rootGroup()); m_rootGroup->merge(other->rootGroup());
for (Uuid customIconId : other->metadata()->customIcons().keys()) { for (const QUuid& customIconId : other->metadata()->customIcons().keys()) {
QImage customIcon = other->metadata()->customIcon(customIconId); QImage customIcon = other->metadata()->customIcon(customIconId);
if (!this->metadata()->containsCustomIcon(customIconId)) { if (!this->metadata()->containsCustomIcon(customIconId)) {
qDebug("Adding custom icon %s to database.", qPrintable(customIconId.toHex())); qDebug() << QString("Adding custom icon %1 to database.").arg(customIconId.toString());
this->metadata()->addCustomIcon(customIconId, customIcon); this->metadata()->addCustomIcon(customIconId, customIcon);
} }
} }
@ -407,12 +408,12 @@ void Database::setEmitModified(bool value)
m_emitModified = value; m_emitModified = value;
} }
Uuid Database::uuid() const QUuid& Database::uuid()
{ {
return m_uuid; return m_uuid;
} }
Database* Database::databaseByUuid(const Uuid& uuid) Database* Database::databaseByUuid(const QUuid& uuid)
{ {
return m_uuidMap.value(uuid, 0); return m_uuidMap.value(uuid, 0);
} }

View File

@ -23,7 +23,6 @@
#include <QHash> #include <QHash>
#include <QObject> #include <QObject>
#include "core/Uuid.h"
#include "crypto/kdf/Kdf.h" #include "crypto/kdf/Kdf.h"
#include "keys/CompositeKey.h" #include "keys/CompositeKey.h"
@ -36,7 +35,7 @@ class QIODevice;
struct DeletedObject struct DeletedObject
{ {
Uuid uuid; QUuid uuid;
QDateTime deletionTime; QDateTime deletionTime;
}; };
@ -56,7 +55,7 @@ public:
struct DatabaseData struct DatabaseData
{ {
Uuid cipher; QUuid cipher;
CompressionAlgorithm compressionAlgo; CompressionAlgorithm compressionAlgo;
QByteArray transformedMasterKey; QByteArray transformedMasterKey;
QSharedPointer<Kdf> kdf; QSharedPointer<Kdf> kdf;
@ -83,14 +82,14 @@ public:
Metadata* metadata(); Metadata* metadata();
const Metadata* metadata() const; const Metadata* metadata() const;
Entry* resolveEntry(const Uuid& uuid); Entry* resolveEntry(const QUuid& uuid);
Entry* resolveEntry(const QString& text, EntryReferenceType referenceType); Entry* resolveEntry(const QString& text, EntryReferenceType referenceType);
Group* resolveGroup(const Uuid& uuid); Group* resolveGroup(const QUuid& uuid);
QList<DeletedObject> deletedObjects(); QList<DeletedObject> deletedObjects();
void addDeletedObject(const DeletedObject& delObj); void addDeletedObject(const DeletedObject& delObj);
void addDeletedObject(const Uuid& uuid); void addDeletedObject(const QUuid& uuid);
Uuid cipher() const; const QUuid& cipher() const;
Database::CompressionAlgorithm compressionAlgo() const; Database::CompressionAlgorithm compressionAlgo() const;
QSharedPointer<Kdf> kdf() const; QSharedPointer<Kdf> kdf() const;
QByteArray transformedMasterKey() const; QByteArray transformedMasterKey() const;
@ -98,7 +97,7 @@ public:
QByteArray challengeResponseKey() const; QByteArray challengeResponseKey() const;
bool challengeMasterSeed(const QByteArray& masterSeed); bool challengeMasterSeed(const QByteArray& masterSeed);
void setCipher(const Uuid& cipher); void setCipher(const QUuid& cipher);
void setCompressionAlgo(Database::CompressionAlgorithm algo); void setCompressionAlgo(Database::CompressionAlgorithm algo);
void setKdf(QSharedPointer<Kdf> kdf); void setKdf(QSharedPointer<Kdf> kdf);
bool setKey(const CompositeKey& key, bool updateChangedTime = true, bool updateTransformSalt = false); bool setKey(const CompositeKey& key, bool updateChangedTime = true, bool updateTransformSalt = false);
@ -117,10 +116,10 @@ public:
/** /**
* Returns a unique id that is only valid as long as the Database exists. * Returns a unique id that is only valid as long as the Database exists.
*/ */
Uuid uuid(); const QUuid& uuid();
bool changeKdf(QSharedPointer<Kdf> kdf); bool changeKdf(QSharedPointer<Kdf> kdf);
static Database* databaseByUuid(const Uuid& uuid); static Database* databaseByUuid(const QUuid& uuid);
static Database* openDatabaseFile(QString fileName, CompositeKey key); static Database* openDatabaseFile(QString fileName, CompositeKey key);
static Database* unlockFromStdin(QString databaseFilename, QString keyFilename = QString("")); static Database* unlockFromStdin(QString databaseFilename, QString keyFilename = QString(""));
@ -140,9 +139,9 @@ private slots:
void startModifiedTimer(); void startModifiedTimer();
private: private:
Entry* findEntryRecursive(const Uuid& uuid, Group* group); Entry* findEntryRecursive(const QUuid& uuid, Group* group);
Entry* findEntryRecursive(const QString& text, EntryReferenceType referenceType, Group* group); Entry* findEntryRecursive(const QString& text, EntryReferenceType referenceType, Group* group);
Group* findGroupRecursive(const Uuid& uuid, Group* group); Group* findGroupRecursive(const QUuid& uuid, Group* group);
void createRecycleBin(); void createRecycleBin();
QString writeDatabase(QIODevice* device); QString writeDatabase(QIODevice* device);
@ -155,8 +154,8 @@ private:
DatabaseData m_data; DatabaseData m_data;
bool m_emitModified; bool m_emitModified;
Uuid m_uuid; QUuid m_uuid;
static QHash<Uuid, Database*> m_uuidMap; static QHash<QUuid, Database*> m_uuidMap;
}; };
#endif // KEEPASSX_DATABASE_H #endif // KEEPASSX_DATABASE_H

View File

@ -25,6 +25,7 @@
#include "core/Metadata.h" #include "core/Metadata.h"
#include "totp/totp.h" #include "totp/totp.h"
#include <QDebug>
#include <QRegularExpression> #include <QRegularExpression>
const int Entry::DefaultIconNumber = 0; const int Entry::DefaultIconNumber = 0;
@ -110,7 +111,7 @@ EntryReferenceType Entry::referenceType(const QString& referenceStr)
} else if (referenceLowerStr == QLatin1String("n")) { } else if (referenceLowerStr == QLatin1String("n")) {
result = EntryReferenceType::Notes; result = EntryReferenceType::Notes;
} else if (referenceLowerStr == QLatin1String("i")) { } else if (referenceLowerStr == QLatin1String("i")) {
result = EntryReferenceType::Uuid; result = EntryReferenceType::QUuid;
} else if (referenceLowerStr == QLatin1String("o")) { } else if (referenceLowerStr == QLatin1String("o")) {
result = EntryReferenceType::CustomAttributes; result = EntryReferenceType::CustomAttributes;
} }
@ -118,7 +119,7 @@ EntryReferenceType Entry::referenceType(const QString& referenceStr)
return result; return result;
} }
Uuid Entry::uuid() const const QUuid& Entry::uuid() const
{ {
return m_uuid; return m_uuid;
} }
@ -170,7 +171,7 @@ int Entry::iconNumber() const
return m_data.iconNumber; return m_data.iconNumber;
} }
Uuid Entry::iconUuid() const const QUuid& Entry::iconUuid() const
{ {
return m_data.customIcon; return m_data.customIcon;
} }
@ -417,7 +418,7 @@ quint8 Entry::totpDigits() const
return m_data.totpDigits; return m_data.totpDigits;
} }
void Entry::setUuid(const Uuid& uuid) void Entry::setUuid(const QUuid& uuid)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
set(m_uuid, uuid); set(m_uuid, uuid);
@ -429,14 +430,14 @@ void Entry::setIcon(int iconNumber)
if (m_data.iconNumber != iconNumber || !m_data.customIcon.isNull()) { if (m_data.iconNumber != iconNumber || !m_data.customIcon.isNull()) {
m_data.iconNumber = iconNumber; m_data.iconNumber = iconNumber;
m_data.customIcon = Uuid(); m_data.customIcon = QUuid();
emit modified(); emit modified();
emitDataChanged(); emitDataChanged();
} }
} }
void Entry::setIcon(const Uuid& uuid) void Entry::setIcon(const QUuid& uuid)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
@ -632,7 +633,7 @@ Entry* Entry::clone(CloneFlags flags) const
Entry* entry = new Entry(); Entry* entry = new Entry();
entry->setUpdateTimeinfo(false); entry->setUpdateTimeinfo(false);
if (flags & CloneNewUuid) { if (flags & CloneNewUuid) {
entry->m_uuid = Uuid::random(); entry->m_uuid = QUuid::createUuid();
} else { } else {
entry->m_uuid = m_uuid; entry->m_uuid = m_uuid;
} }
@ -643,15 +644,13 @@ Entry* Entry::clone(CloneFlags flags) const
if (flags & CloneUserAsRef) { if (flags & CloneUserAsRef) {
// Build the username reference // Build the username reference
QString username = "{REF:U@I:" + m_uuid.toHex() + "}"; QString username = "{REF:U@I:" + m_uuid.toRfc4122().toHex() + "}";
entry->m_attributes->set( entry->m_attributes->set(EntryAttributes::UserNameKey, username.toUpper(), m_attributes->isProtected(EntryAttributes::UserNameKey));
EntryAttributes::UserNameKey, username.toUpper(), m_attributes->isProtected(EntryAttributes::UserNameKey));
} }
if (flags & ClonePassAsRef) { if (flags & ClonePassAsRef) {
QString password = "{REF:P@I:" + m_uuid.toHex() + "}"; QString password = "{REF:P@I:" + m_uuid.toRfc4122().toHex() + "}";
entry->m_attributes->set( entry->m_attributes->set(EntryAttributes::PasswordKey, password.toUpper(), m_attributes->isProtected(EntryAttributes::PasswordKey));
EntryAttributes::PasswordKey, password.toUpper(), m_attributes->isProtected(EntryAttributes::PasswordKey));
} }
entry->m_autoTypeAssociations->copyDataFrom(m_autoTypeAssociations); entry->m_autoTypeAssociations->copyDataFrom(m_autoTypeAssociations);
@ -757,7 +756,7 @@ void Entry::updateTotp()
QString Entry::resolveMultiplePlaceholdersRecursive(const QString& str, int maxDepth) const QString Entry::resolveMultiplePlaceholdersRecursive(const QString& str, int maxDepth) const
{ {
if (maxDepth <= 0) { if (maxDepth <= 0) {
qWarning("Maximum depth of replacement has been reached. Entry uuid: %s", qPrintable(uuid().toHex())); qWarning() << QString("Maximum depth of replacement has been reached. Entry uuid: %1").arg(uuid().toString());
return str; return str;
} }
@ -781,7 +780,7 @@ QString Entry::resolveMultiplePlaceholdersRecursive(const QString& str, int maxD
QString Entry::resolvePlaceholderRecursive(const QString& placeholder, int maxDepth) const QString Entry::resolvePlaceholderRecursive(const QString& placeholder, int maxDepth) const
{ {
if (maxDepth <= 0) { if (maxDepth <= 0) {
qWarning("Maximum depth of replacement has been reached. Entry uuid: %s", qPrintable(uuid().toHex())); qWarning() << QString("Maximum depth of replacement has been reached. Entry uuid: %1").arg(uuid().toString());
return placeholder; return placeholder;
} }
@ -845,7 +844,7 @@ QString Entry::resolvePlaceholderRecursive(const QString& placeholder, int maxDe
QString Entry::resolveReferencePlaceholderRecursive(const QString& placeholder, int maxDepth) const QString Entry::resolveReferencePlaceholderRecursive(const QString& placeholder, int maxDepth) const
{ {
if (maxDepth <= 0) { if (maxDepth <= 0) {
qWarning("Maximum depth of replacement has been reached. Entry uuid: %s", qPrintable(uuid().toHex())); qWarning() << QString("Maximum depth of replacement has been reached. Entry uuid: %1").arg(uuid().toString());
return placeholder; return placeholder;
} }
@ -893,8 +892,8 @@ QString Entry::referenceFieldValue(EntryReferenceType referenceType) const
return url(); return url();
case EntryReferenceType::Notes: case EntryReferenceType::Notes:
return notes(); return notes();
case EntryReferenceType::Uuid: case EntryReferenceType::QUuid:
return uuid().toHex(); return uuid().toRfc4122().toHex();
default: default:
break; break;
} }

View File

@ -26,13 +26,13 @@
#include <QPointer> #include <QPointer>
#include <QSet> #include <QSet>
#include <QUrl> #include <QUrl>
#include <QUuid>
#include "core/AutoTypeAssociations.h" #include "core/AutoTypeAssociations.h"
#include "core/CustomData.h" #include "core/CustomData.h"
#include "core/EntryAttachments.h" #include "core/EntryAttachments.h"
#include "core/EntryAttributes.h" #include "core/EntryAttributes.h"
#include "core/TimeInfo.h" #include "core/TimeInfo.h"
#include "core/Uuid.h"
class Database; class Database;
class Group; class Group;
@ -45,14 +45,14 @@ enum class EntryReferenceType
Password, Password,
Url, Url,
Notes, Notes,
Uuid, QUuid,
CustomAttributes CustomAttributes
}; };
struct EntryData struct EntryData
{ {
int iconNumber; int iconNumber;
Uuid customIcon; QUuid customIcon;
QColor foregroundColor; QColor foregroundColor;
QColor backgroundColor; QColor backgroundColor;
QString overrideUrl; QString overrideUrl;
@ -72,12 +72,12 @@ class Entry : public QObject
public: public:
Entry(); Entry();
~Entry(); ~Entry();
Uuid uuid() const; const QUuid& uuid() const;
QImage icon() const; QImage icon() const;
QPixmap iconPixmap() const; QPixmap iconPixmap() const;
QPixmap iconScaledPixmap() const; QPixmap iconScaledPixmap() const;
int iconNumber() const; int iconNumber() const;
Uuid iconUuid() const; const QUuid& iconUuid() const;
QColor foregroundColor() const; QColor foregroundColor() const;
QColor backgroundColor() const; QColor backgroundColor() const;
QString overrideUrl() const; QString overrideUrl() const;
@ -117,9 +117,9 @@ public:
static const QString AutoTypeSequenceUsername; static const QString AutoTypeSequenceUsername;
static const QString AutoTypeSequencePassword; static const QString AutoTypeSequencePassword;
void setUuid(const Uuid& uuid); void setUuid(const QUuid& uuid);
void setIcon(int iconNumber); void setIcon(int iconNumber);
void setIcon(const Uuid& uuid); void setIcon(const QUuid& uuid);
void setForegroundColor(const QColor& color); void setForegroundColor(const QColor& color);
void setBackgroundColor(const QColor& color); void setBackgroundColor(const QColor& color);
void setOverrideUrl(const QString& url); void setOverrideUrl(const QString& url);
@ -232,7 +232,7 @@ private:
const Database* database() const; const Database* database() const;
template <class T> bool set(T& property, const T& value); template <class T> bool set(T& property, const T& value);
Uuid m_uuid; QUuid m_uuid;
EntryData m_data; EntryData m_data;
QPointer<EntryAttributes> m_attributes; QPointer<EntryAttributes> m_attributes;
QPointer<EntryAttachments> m_attachments; QPointer<EntryAttachments> m_attachments;

View File

@ -73,7 +73,7 @@ Group::~Group()
Group* Group::createRecycleBin() Group* Group::createRecycleBin()
{ {
Group* recycleBin = new Group(); Group* recycleBin = new Group();
recycleBin->setUuid(Uuid::random()); recycleBin->setUuid(QUuid::createUuid());
recycleBin->setName(tr("Recycle Bin")); recycleBin->setName(tr("Recycle Bin"));
recycleBin->setIcon(RecycleBinIconNumber); recycleBin->setIcon(RecycleBinIconNumber);
recycleBin->setSearchingEnabled(Group::Disable); recycleBin->setSearchingEnabled(Group::Disable);
@ -105,7 +105,7 @@ void Group::setUpdateTimeinfo(bool value)
m_updateTimeinfo = value; m_updateTimeinfo = value;
} }
Uuid Group::uuid() const const QUuid& Group::uuid() const
{ {
return m_uuid; return m_uuid;
} }
@ -171,7 +171,7 @@ int Group::iconNumber() const
return m_data.iconNumber; return m_data.iconNumber;
} }
Uuid Group::iconUuid() const const QUuid& Group::iconUuid() const
{ {
return m_data.customIcon; return m_data.customIcon;
} }
@ -259,7 +259,7 @@ const CustomData* Group::customData() const
return m_customData; return m_customData;
} }
void Group::setUuid(const Uuid& uuid) void Group::setUuid(const QUuid& uuid)
{ {
set(m_uuid, uuid); set(m_uuid, uuid);
} }
@ -282,13 +282,13 @@ void Group::setIcon(int iconNumber)
if (m_data.iconNumber != iconNumber || !m_data.customIcon.isNull()) { if (m_data.iconNumber != iconNumber || !m_data.customIcon.isNull()) {
m_data.iconNumber = iconNumber; m_data.iconNumber = iconNumber;
m_data.customIcon = Uuid(); m_data.customIcon = QUuid();
emit modified(); emit modified();
emit dataChanged(this); emit dataChanged(this);
} }
} }
void Group::setIcon(const Uuid& uuid) void Group::setIcon(const QUuid& uuid)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
@ -514,8 +514,9 @@ Entry* Group::findEntry(QString entryId)
Q_ASSERT(!entryId.isNull()); Q_ASSERT(!entryId.isNull());
Entry* entry; Entry* entry;
if (Uuid::isUuid(entryId)) { QUuid entryUuid = QUuid::fromRfc4122(QByteArray::fromHex(entryId.toLatin1()));
entry = findEntryByUuid(Uuid::fromHex(entryId)); if (!entryUuid.isNull()) {
entry = findEntryByUuid(entryUuid);
if (entry) { if (entry) {
return entry; return entry;
} }
@ -535,7 +536,7 @@ Entry* Group::findEntry(QString entryId)
return nullptr; return nullptr;
} }
Entry* Group::findEntryByUuid(const Uuid& uuid) Entry* Group::findEntryByUuid(const QUuid& uuid)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
for (Entry* entry : entriesRecursive(false)) { for (Entry* entry : entriesRecursive(false)) {
@ -654,9 +655,9 @@ QList<Group*> Group::groupsRecursive(bool includeSelf)
return groupList; return groupList;
} }
QSet<Uuid> Group::customIconsRecursive() const QSet<QUuid> Group::customIconsRecursive() const
{ {
QSet<Uuid> result; QSet<QUuid> result;
if (!iconUuid().isNull()) { if (!iconUuid().isNull()) {
result.insert(iconUuid()); result.insert(iconUuid());
@ -730,7 +731,7 @@ void Group::merge(const Group* other)
emit modified(); emit modified();
} }
Group* Group::findChildByUuid(const Uuid& uuid) Group* Group::findChildByUuid(const QUuid& uuid)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
for (Group* group : groupsRecursive(true)) { for (Group* group : groupsRecursive(true)) {
@ -760,7 +761,7 @@ Group* Group::clone(Entry::CloneFlags entryFlags, Group::CloneFlags groupFlags)
clonedGroup->setUpdateTimeinfo(false); clonedGroup->setUpdateTimeinfo(false);
if (groupFlags & Group::CloneNewUuid) { if (groupFlags & Group::CloneNewUuid) {
clonedGroup->setUuid(Uuid::random()); clonedGroup->setUuid(QUuid::createUuid());
} else { } else {
clonedGroup->setUuid(this->uuid()); clonedGroup->setUuid(this->uuid());
} }
@ -1042,7 +1043,7 @@ Entry* Group::addEntryWithPath(QString entryPath)
Entry* entry = new Entry(); Entry* entry = new Entry();
entry->setTitle(entryTitle); entry->setTitle(entryTitle);
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
entry->setGroup(group); entry->setGroup(group);
return entry; return entry;

View File

@ -28,7 +28,6 @@
#include "core/Database.h" #include "core/Database.h"
#include "core/Entry.h" #include "core/Entry.h"
#include "core/TimeInfo.h" #include "core/TimeInfo.h"
#include "core/Uuid.h"
class Group : public QObject class Group : public QObject
{ {
@ -63,7 +62,7 @@ public:
QString name; QString name;
QString notes; QString notes;
int iconNumber; int iconNumber;
Uuid customIcon; QUuid customIcon;
TimeInfo timeInfo; TimeInfo timeInfo;
bool isExpanded; bool isExpanded;
QString defaultAutoTypeSequence; QString defaultAutoTypeSequence;
@ -77,14 +76,14 @@ public:
static Group* createRecycleBin(); static Group* createRecycleBin();
Uuid uuid() const; const QUuid& uuid() const;
QString name() const; QString name() const;
QString notes() const; QString notes() const;
QImage icon() const; QImage icon() const;
QPixmap iconPixmap() const; QPixmap iconPixmap() const;
QPixmap iconScaledPixmap() const; QPixmap iconScaledPixmap() const;
int iconNumber() const; int iconNumber() const;
Uuid iconUuid() const; const QUuid& iconUuid() const;
TimeInfo timeInfo() const; TimeInfo timeInfo() const;
bool isExpanded() const; bool isExpanded() const;
QString defaultAutoTypeSequence() const; QString defaultAutoTypeSequence() const;
@ -106,18 +105,18 @@ public:
static const QString RootAutoTypeSequence; static const QString RootAutoTypeSequence;
Group* findChildByName(const QString& name); Group* findChildByName(const QString& name);
Group* findChildByUuid(const Uuid& uuid); Group* findChildByUuid(const QUuid& uuid);
Entry* findEntry(QString entryId); Entry* findEntry(QString entryId);
Entry* findEntryByUuid(const Uuid& uuid); Entry* findEntryByUuid(const QUuid& uuid);
Entry* findEntryByPath(QString entryPath, QString basePath = QString("")); Entry* findEntryByPath(QString entryPath, QString basePath = QString(""));
Group* findGroupByPath(QString groupPath, QString basePath = QString("/")); Group* findGroupByPath(QString groupPath, QString basePath = QString("/"));
QStringList locate(QString locateTerm, QString currentPath = QString("/")); QStringList locate(QString locateTerm, QString currentPath = QString("/"));
Entry* addEntryWithPath(QString entryPath); Entry* addEntryWithPath(QString entryPath);
void setUuid(const Uuid& uuid); void setUuid(const QUuid& uuid);
void setName(const QString& name); void setName(const QString& name);
void setNotes(const QString& notes); void setNotes(const QString& notes);
void setIcon(int iconNumber); void setIcon(int iconNumber);
void setIcon(const Uuid& uuid); void setIcon(const QUuid& uuid);
void setTimeInfo(const TimeInfo& timeInfo); void setTimeInfo(const TimeInfo& timeInfo);
void setExpanded(bool expanded); void setExpanded(bool expanded);
void setDefaultAutoTypeSequence(const QString& sequence); void setDefaultAutoTypeSequence(const QString& sequence);
@ -144,7 +143,7 @@ public:
QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const; QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const;
QList<const Group*> groupsRecursive(bool includeSelf) const; QList<const Group*> groupsRecursive(bool includeSelf) const;
QList<Group*> groupsRecursive(bool includeSelf); QList<Group*> groupsRecursive(bool includeSelf);
QSet<Uuid> customIconsRecursive() const; QSet<QUuid> customIconsRecursive() const;
/** /**
* Creates a duplicate of this group. * Creates a duplicate of this group.
* Note that you need to copy the custom icons manually when inserting the * Note that you need to copy the custom icons manually when inserting the
@ -197,7 +196,7 @@ private:
void recCreateDelObjects(); void recCreateDelObjects();
QPointer<Database> m_db; QPointer<Database> m_db;
Uuid m_uuid; QUuid m_uuid;
GroupData m_data; GroupData m_data;
QPointer<Entry> m_lastTopVisibleEntry; QPointer<Entry> m_lastTopVisibleEntry;
QList<Group*> m_children; QList<Group*> m_children;

View File

@ -160,12 +160,12 @@ bool Metadata::protectNotes() const
return m_data.protectNotes; return m_data.protectNotes;
} }
QImage Metadata::customIcon(const Uuid& uuid) const QImage Metadata::customIcon(const QUuid& uuid) const
{ {
return m_customIcons.value(uuid); return m_customIcons.value(uuid);
} }
QPixmap Metadata::customIconPixmap(const Uuid& uuid) const QPixmap Metadata::customIconPixmap(const QUuid& uuid) const
{ {
QPixmap pixmap; QPixmap pixmap;
@ -183,7 +183,7 @@ QPixmap Metadata::customIconPixmap(const Uuid& uuid) const
return pixmap; return pixmap;
} }
QPixmap Metadata::customIconScaledPixmap(const Uuid& uuid) const QPixmap Metadata::customIconScaledPixmap(const QUuid& uuid) const
{ {
QPixmap pixmap; QPixmap pixmap;
@ -202,28 +202,28 @@ QPixmap Metadata::customIconScaledPixmap(const Uuid& uuid) const
return pixmap; return pixmap;
} }
bool Metadata::containsCustomIcon(const Uuid& uuid) const bool Metadata::containsCustomIcon(const QUuid& uuid) const
{ {
return m_customIcons.contains(uuid); return m_customIcons.contains(uuid);
} }
QHash<Uuid, QImage> Metadata::customIcons() const QHash<QUuid, QImage> Metadata::customIcons() const
{ {
return m_customIcons; return m_customIcons;
} }
QHash<Uuid, QPixmap> Metadata::customIconsScaledPixmaps() const QHash<QUuid, QPixmap> Metadata::customIconsScaledPixmaps() const
{ {
QHash<Uuid, QPixmap> result; QHash<QUuid, QPixmap> result;
for (const Uuid& uuid : m_customIconsOrder) { for (const QUuid& uuid : m_customIconsOrder) {
result.insert(uuid, customIconScaledPixmap(uuid)); result.insert(uuid, customIconScaledPixmap(uuid));
} }
return result; return result;
} }
QList<Uuid> Metadata::customIconsOrder() const QList<QUuid> Metadata::customIconsOrder() const
{ {
return m_customIconsOrder; return m_customIconsOrder;
} }
@ -378,7 +378,7 @@ void Metadata::setProtectNotes(bool value)
set(m_data.protectNotes, value); set(m_data.protectNotes, value);
} }
void Metadata::addCustomIcon(const Uuid& uuid, const QImage& icon) void Metadata::addCustomIcon(const QUuid& uuid, const QImage& icon)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
Q_ASSERT(!m_customIcons.contains(uuid)); Q_ASSERT(!m_customIcons.contains(uuid));
@ -395,7 +395,7 @@ void Metadata::addCustomIcon(const Uuid& uuid, const QImage& icon)
emit modified(); emit modified();
} }
void Metadata::addCustomIconScaled(const Uuid& uuid, const QImage& icon) void Metadata::addCustomIconScaled(const QUuid& uuid, const QImage& icon)
{ {
QImage iconScaled; QImage iconScaled;
@ -409,7 +409,7 @@ void Metadata::addCustomIconScaled(const Uuid& uuid, const QImage& icon)
addCustomIcon(uuid, iconScaled); addCustomIcon(uuid, iconScaled);
} }
void Metadata::removeCustomIcon(const Uuid& uuid) void Metadata::removeCustomIcon(const QUuid& uuid)
{ {
Q_ASSERT(!uuid.isNull()); Q_ASSERT(!uuid.isNull());
Q_ASSERT(m_customIcons.contains(uuid)); Q_ASSERT(m_customIcons.contains(uuid));
@ -430,15 +430,15 @@ void Metadata::removeCustomIcon(const Uuid& uuid)
emit modified(); emit modified();
} }
Uuid Metadata::findCustomIcon(const QImage& candidate) QUuid Metadata::findCustomIcon(const QImage &candidate)
{ {
QByteArray hash = hashImage(candidate); QByteArray hash = hashImage(candidate);
return m_customIconsHashes.value(hash, Uuid()); return m_customIconsHashes.value(hash, QUuid());
} }
void Metadata::copyCustomIcons(const QSet<Uuid>& iconList, const Metadata* otherMetadata) void Metadata::copyCustomIcons(const QSet<QUuid>& iconList, const Metadata* otherMetadata)
{ {
for (const Uuid& uuid : iconList) { for (const QUuid& uuid : iconList) {
Q_ASSERT(otherMetadata->containsCustomIcon(uuid)); Q_ASSERT(otherMetadata->containsCustomIcon(uuid));
if (!containsCustomIcon(uuid) && otherMetadata->containsCustomIcon(uuid)) { if (!containsCustomIcon(uuid) && otherMetadata->containsCustomIcon(uuid)) {

View File

@ -25,9 +25,9 @@
#include <QPixmap> #include <QPixmap>
#include <QPixmapCache> #include <QPixmapCache>
#include <QPointer> #include <QPointer>
#include <QUuid>
#include "core/CustomData.h" #include "core/CustomData.h"
#include "core/Uuid.h"
class Database; class Database;
class Group; class Group;
@ -78,14 +78,14 @@ public:
bool protectPassword() const; bool protectPassword() const;
bool protectUrl() const; bool protectUrl() const;
bool protectNotes() const; bool protectNotes() const;
QImage customIcon(const Uuid& uuid) const; QImage customIcon(const QUuid& uuid) const;
QPixmap customIconPixmap(const Uuid& uuid) const; QPixmap customIconPixmap(const QUuid& uuid) const;
QPixmap customIconScaledPixmap(const Uuid& uuid) const; QPixmap customIconScaledPixmap(const QUuid& uuid) const;
bool containsCustomIcon(const Uuid& uuid) const; bool containsCustomIcon(const QUuid& uuid) const;
QHash<Uuid, QImage> customIcons() const; QHash<QUuid, QImage> customIcons() const;
QList<Uuid> customIconsOrder() const; QList<QUuid> customIconsOrder() const;
bool recycleBinEnabled() const; bool recycleBinEnabled() const;
QHash<Uuid, QPixmap> customIconsScaledPixmaps() const; QHash<QUuid, QPixmap> customIconsScaledPixmaps() const;
Group* recycleBin(); Group* recycleBin();
const Group* recycleBin() const; const Group* recycleBin() const;
QDateTime recycleBinChanged() const; QDateTime recycleBinChanged() const;
@ -119,11 +119,11 @@ public:
void setProtectPassword(bool value); void setProtectPassword(bool value);
void setProtectUrl(bool value); void setProtectUrl(bool value);
void setProtectNotes(bool value); void setProtectNotes(bool value);
void addCustomIcon(const Uuid& uuid, const QImage& icon); void addCustomIcon(const QUuid& uuid, const QImage& icon);
void addCustomIconScaled(const Uuid& uuid, const QImage& icon); void addCustomIconScaled(const QUuid& uuid, const QImage& icon);
void removeCustomIcon(const Uuid& uuid); void removeCustomIcon(const QUuid& uuid);
void copyCustomIcons(const QSet<Uuid>& iconList, const Metadata* otherMetadata); void copyCustomIcons(const QSet<QUuid>& iconList, const Metadata* otherMetadata);
Uuid findCustomIcon(const QImage& candidate); QUuid findCustomIcon(const QImage& candidate);
void setRecycleBinEnabled(bool value); void setRecycleBinEnabled(bool value);
void setRecycleBin(Group* group); void setRecycleBin(Group* group);
void setRecycleBinChanged(const QDateTime& value); void setRecycleBinChanged(const QDateTime& value);
@ -159,11 +159,11 @@ private:
MetadataData m_data; MetadataData m_data;
QHash<Uuid, QImage> m_customIcons; QHash<QUuid, QImage> m_customIcons;
mutable QHash<Uuid, QPixmapCache::Key> m_customIconCacheKeys; mutable QHash<QUuid, QPixmapCache::Key> m_customIconCacheKeys;
mutable QHash<Uuid, QPixmapCache::Key> m_customIconScaledCacheKeys; mutable QHash<QUuid, QPixmapCache::Key> m_customIconScaledCacheKeys;
QList<Uuid> m_customIconsOrder; QList<QUuid> m_customIconsOrder;
QHash<QByteArray, Uuid> m_customIconsHashes; QHash<QByteArray, QUuid> m_customIconsHashes;
QPointer<Group> m_recycleBin; QPointer<Group> m_recycleBin;
QDateTime m_recycleBinChanged; QDateTime m_recycleBinChanged;

View File

@ -17,8 +17,6 @@
#include "TimeInfo.h" #include "TimeInfo.h"
#include "core/Tools.h"
TimeInfo::TimeInfo() TimeInfo::TimeInfo()
: m_expires(false) : m_expires(false)
, m_usageCount(0) , m_usageCount(0)

View File

@ -1,124 +0,0 @@
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Uuid.h"
#include <QHash>
#include "crypto/Random.h"
const int Uuid::Length = 16;
const QRegExp Uuid::HexRegExp =
QRegExp(QString("^[0-9A-F]{%1}$").arg(QString::number(Uuid::Length * 2)), Qt::CaseInsensitive);
Uuid::Uuid()
: m_data(Length, 0)
{
}
Uuid::Uuid(const QByteArray& data)
{
Q_ASSERT(data.size() == Length);
m_data = data;
}
Uuid Uuid::random()
{
return Uuid(randomGen()->randomArray(Length));
}
QString Uuid::toBase64() const
{
return QString::fromLatin1(m_data.toBase64());
}
QString Uuid::toHex() const
{
return QString::fromLatin1(m_data.toHex());
}
QByteArray Uuid::toByteArray() const
{
return m_data;
}
bool Uuid::isNull() const
{
for (int i = 0; i < m_data.size(); ++i) {
if (m_data[i] != 0) {
return false;
}
}
return true;
}
Uuid& Uuid::operator=(const Uuid& other)
{
m_data = other.m_data;
return *this;
}
bool Uuid::operator==(const Uuid& other) const
{
return m_data == other.m_data;
}
bool Uuid::operator!=(const Uuid& other) const
{
return !operator==(other);
}
Uuid Uuid::fromBase64(const QString& str)
{
QByteArray data = QByteArray::fromBase64(str.toLatin1());
return Uuid(data);
}
Uuid Uuid::fromHex(const QString& str)
{
QByteArray data = QByteArray::fromHex(str.toLatin1());
return Uuid(data);
}
uint qHash(const Uuid& key)
{
return qHash(key.toByteArray());
}
QDataStream& operator<<(QDataStream& stream, const Uuid& uuid)
{
return stream << uuid.toByteArray();
}
QDataStream& operator>>(QDataStream& stream, Uuid& uuid)
{
QByteArray data;
stream >> data;
if (data.size() == Uuid::Length) {
uuid = Uuid(data);
}
return stream;
}
bool Uuid::isUuid(const QString& uuid)
{
return Uuid::HexRegExp.exactMatch(uuid);
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_UUID_H
#define KEEPASSX_UUID_H
#include <QByteArray>
#include <QRegExp>
#include <QString>
class Uuid
{
public:
Uuid();
explicit Uuid(const QByteArray& data);
static Uuid random();
QString toBase64() const;
QString toHex() const;
QByteArray toByteArray() const;
bool isNull() const;
Uuid& operator=(const Uuid& other);
bool operator==(const Uuid& other) const;
bool operator!=(const Uuid& other) const;
static const int Length;
static const QRegExp HexRegExp;
static Uuid fromBase64(const QString& str);
static Uuid fromHex(const QString& str);
static bool isUuid(const QString& str);
private:
QByteArray m_data;
};
Q_DECLARE_TYPEINFO(Uuid, Q_MOVABLE_TYPE);
uint qHash(const Uuid& key);
QDataStream& operator<<(QDataStream& stream, const Uuid& uuid);
QDataStream& operator>>(QDataStream& stream, Uuid& uuid);
#endif // KEEPASSX_UUID_H

View File

@ -20,6 +20,8 @@
#include "config-keepassx.h" #include "config-keepassx.h"
#include "crypto/SymmetricCipherGcrypt.h" #include "crypto/SymmetricCipherGcrypt.h"
#include <QDebug>
SymmetricCipher::SymmetricCipher(Algorithm algo, Mode mode, Direction direction) SymmetricCipher::SymmetricCipher(Algorithm algo, Mode mode, Direction direction)
: m_backend(createBackend(algo, mode, direction)) : m_backend(createBackend(algo, mode, direction))
, m_initialized(false) , m_initialized(false)
@ -90,7 +92,7 @@ QString SymmetricCipher::errorString() const
return m_backend->errorString(); return m_backend->errorString();
} }
SymmetricCipher::Algorithm SymmetricCipher::cipherToAlgorithm(Uuid cipher) SymmetricCipher::Algorithm SymmetricCipher::cipherToAlgorithm(const QUuid& cipher)
{ {
if (cipher == KeePass2::CIPHER_AES) { if (cipher == KeePass2::CIPHER_AES) {
return Aes256; return Aes256;
@ -100,11 +102,11 @@ SymmetricCipher::Algorithm SymmetricCipher::cipherToAlgorithm(Uuid cipher)
return Twofish; return Twofish;
} }
qWarning("SymmetricCipher::cipherToAlgorithm: invalid Uuid %s", cipher.toByteArray().toHex().data()); qWarning() << "SymmetricCipher::cipherToAlgorithm: invalid UUID " << cipher;
return InvalidAlgorithm; return InvalidAlgorithm;
} }
Uuid SymmetricCipher::algorithmToCipher(Algorithm algo) QUuid SymmetricCipher::algorithmToCipher(Algorithm algo)
{ {
switch (algo) { switch (algo) {
case Aes256: case Aes256:
@ -115,7 +117,7 @@ Uuid SymmetricCipher::algorithmToCipher(Algorithm algo)
return KeePass2::CIPHER_TWOFISH; return KeePass2::CIPHER_TWOFISH;
default: default:
qWarning("SymmetricCipher::algorithmToCipher: invalid algorithm %d", algo); qWarning("SymmetricCipher::algorithmToCipher: invalid algorithm %d", algo);
return Uuid(); return QUuid();
} }
} }

View File

@ -21,8 +21,8 @@
#include <QByteArray> #include <QByteArray>
#include <QScopedPointer> #include <QScopedPointer>
#include <QString> #include <QString>
#include <QUuid>
#include "core/Uuid.h"
#include "crypto/SymmetricCipherBackend.h" #include "crypto/SymmetricCipherBackend.h"
#include "format/KeePass2.h" #include "format/KeePass2.h"
@ -83,8 +83,8 @@ public:
QString errorString() const; QString errorString() const;
Algorithm algorithm() const; Algorithm algorithm() const;
static Algorithm cipherToAlgorithm(Uuid cipher); static Algorithm cipherToAlgorithm(const QUuid& cipher);
static Uuid algorithmToCipher(Algorithm algo); static QUuid algorithmToCipher(Algorithm algo);
static int algorithmIvSize(Algorithm algo); static int algorithmIvSize(Algorithm algo);
static Mode algorithmMode(Algorithm algo); static Mode algorithmMode(Algorithm algo);

View File

@ -52,7 +52,7 @@ QVariantMap AesKdf::writeParameters()
QVariantMap p; QVariantMap p;
// always write old KDBX3 AES-KDF UUID for compatibility with other applications // always write old KDBX3 AES-KDF UUID for compatibility with other applications
p.insert(KeePass2::KDFPARAM_UUID, KeePass2::KDF_AES_KDBX3.toByteArray()); p.insert(KeePass2::KDFPARAM_UUID, KeePass2::KDF_AES_KDBX3.toRfc4122());
p.insert(KeePass2::KDFPARAM_AES_ROUNDS, static_cast<quint64>(rounds())); p.insert(KeePass2::KDFPARAM_AES_ROUNDS, static_cast<quint64>(rounds()));
p.insert(KeePass2::KDFPARAM_AES_SEED, seed()); p.insert(KeePass2::KDFPARAM_AES_SEED, seed());

View File

@ -133,7 +133,7 @@ bool Argon2Kdf::processParameters(const QVariantMap& p)
QVariantMap Argon2Kdf::writeParameters() QVariantMap Argon2Kdf::writeParameters()
{ {
QVariantMap p; QVariantMap p;
p.insert(KeePass2::KDFPARAM_UUID, KeePass2::KDF_ARGON2.toByteArray()); p.insert(KeePass2::KDFPARAM_UUID, KeePass2::KDF_ARGON2.toRfc4122());
p.insert(KeePass2::KDFPARAM_ARGON2_VERSION, version()); p.insert(KeePass2::KDFPARAM_ARGON2_VERSION, version());
p.insert(KeePass2::KDFPARAM_ARGON2_PARALLELISM, parallelism()); p.insert(KeePass2::KDFPARAM_ARGON2_PARALLELISM, parallelism());
p.insert(KeePass2::KDFPARAM_ARGON2_MEMORY, memory() * 1024); p.insert(KeePass2::KDFPARAM_ARGON2_MEMORY, memory() * 1024);

View File

@ -22,14 +22,14 @@
#include "crypto/Random.h" #include "crypto/Random.h"
Kdf::Kdf(Uuid uuid) Kdf::Kdf(const QUuid& uuid)
: m_rounds(KDF_DEFAULT_ROUNDS) : m_rounds(KDF_DEFAULT_ROUNDS)
, m_seed(QByteArray(KDF_DEFAULT_SEED_SIZE, 0)) , m_seed(QByteArray(KDF_DEFAULT_SEED_SIZE, 0))
, m_uuid(uuid) , m_uuid(uuid)
{ {
} }
Uuid Kdf::uuid() const const QUuid& Kdf::uuid() const
{ {
return m_uuid; return m_uuid;
} }

View File

@ -19,8 +19,7 @@
#define KEEPASSX_KDF_H #define KEEPASSX_KDF_H
#include <QVariant> #include <QVariant>
#include <QUuid>
#include "core/Uuid.h"
#define KDF_DEFAULT_SEED_SIZE 32 #define KDF_DEFAULT_SEED_SIZE 32
#define KDF_DEFAULT_ROUNDS 1000000ull #define KDF_DEFAULT_ROUNDS 1000000ull
@ -28,10 +27,10 @@
class Kdf class Kdf
{ {
public: public:
explicit Kdf(Uuid uuid); explicit Kdf(const QUuid& uuid);
virtual ~Kdf() = default; virtual ~Kdf() = default;
Uuid uuid() const; const QUuid& uuid() const;
int rounds() const; int rounds() const;
virtual bool setRounds(int rounds); virtual bool setRounds(int rounds);
@ -54,7 +53,6 @@ protected:
private: private:
class BenchmarkThread; class BenchmarkThread;
const Uuid m_uuid; const QUuid m_uuid;
}; };
#endif // KEEPASSX_KDF_H #endif // KEEPASSX_KDF_H

View File

@ -65,12 +65,10 @@ bool Kdbx3Writer::writeDatabase(QIODevice* device, Database* db)
writeMagicNumbers(&header, KeePass2::SIGNATURE_1, KeePass2::SIGNATURE_2, KeePass2::FILE_VERSION_3_1); writeMagicNumbers(&header, KeePass2::SIGNATURE_1, KeePass2::SIGNATURE_2, KeePass2::FILE_VERSION_3_1);
CHECK_RETURN_FALSE( CHECK_RETURN_FALSE(writeHeaderField<quint16>(&header, KeePass2::HeaderFieldID::CipherID, db->cipher().toRfc4122()));
writeHeaderField<quint16>(&header, KeePass2::HeaderFieldID::CipherID, db->cipher().toByteArray())); CHECK_RETURN_FALSE(writeHeaderField<quint16>(&header, KeePass2::HeaderFieldID::CompressionFlags,
CHECK_RETURN_FALSE( Endian::sizedIntToBytes<qint32>(db->compressionAlgo(),
writeHeaderField<quint16>(&header, KeePass2::BYTEORDER)));
KeePass2::HeaderFieldID::CompressionFlags,
Endian::sizedIntToBytes<qint32>(db->compressionAlgo(), KeePass2::BYTEORDER)));
auto kdf = db->kdf(); auto kdf = db->kdf();
CHECK_RETURN_FALSE(writeHeaderField<quint16>(&header, KeePass2::HeaderFieldID::MasterSeed, masterSeed)); CHECK_RETURN_FALSE(writeHeaderField<quint16>(&header, KeePass2::HeaderFieldID::MasterSeed, masterSeed));
CHECK_RETURN_FALSE(writeHeaderField<quint16>(&header, KeePass2::HeaderFieldID::TransformSeed, kdf->seed())); CHECK_RETURN_FALSE(writeHeaderField<quint16>(&header, KeePass2::HeaderFieldID::TransformSeed, kdf->seed()));

View File

@ -73,12 +73,10 @@ bool Kdbx4Writer::writeDatabase(QIODevice* device, Database* db)
writeMagicNumbers(&header, KeePass2::SIGNATURE_1, KeePass2::SIGNATURE_2, KeePass2::FILE_VERSION_4); writeMagicNumbers(&header, KeePass2::SIGNATURE_1, KeePass2::SIGNATURE_2, KeePass2::FILE_VERSION_4);
CHECK_RETURN_FALSE( CHECK_RETURN_FALSE(writeHeaderField<quint32>(&header, KeePass2::HeaderFieldID::CipherID, db->cipher().toRfc4122()));
writeHeaderField<quint32>(&header, KeePass2::HeaderFieldID::CipherID, db->cipher().toByteArray())); CHECK_RETURN_FALSE(writeHeaderField<quint32>(&header, KeePass2::HeaderFieldID::CompressionFlags,
CHECK_RETURN_FALSE(writeHeaderField<quint32>( Endian::sizedIntToBytes(static_cast<int>(db->compressionAlgo()),
&header, KeePass2::BYTEORDER)));
KeePass2::HeaderFieldID::CompressionFlags,
Endian::sizedIntToBytes(static_cast<int>(db->compressionAlgo()), KeePass2::BYTEORDER)));
CHECK_RETURN_FALSE(writeHeaderField<quint32>(&header, KeePass2::HeaderFieldID::MasterSeed, masterSeed)); CHECK_RETURN_FALSE(writeHeaderField<quint32>(&header, KeePass2::HeaderFieldID::MasterSeed, masterSeed));
CHECK_RETURN_FALSE(writeHeaderField<quint32>(&header, KeePass2::HeaderFieldID::EncryptionIV, encryptionIV)); CHECK_RETURN_FALSE(writeHeaderField<quint32>(&header, KeePass2::HeaderFieldID::EncryptionIV, encryptionIV));

View File

@ -19,6 +19,8 @@
#include "core/Database.h" #include "core/Database.h"
#include "core/Endian.h" #include "core/Endian.h"
#define UUID_LENGTH 16
/** /**
* Read KDBX magic header numbers from a device. * Read KDBX magic header numbers from a device.
* *
@ -133,12 +135,16 @@ KeePass2::ProtectedStreamAlgo KdbxReader::protectedStreamAlgo() const
*/ */
void KdbxReader::setCipher(const QByteArray& data) void KdbxReader::setCipher(const QByteArray& data)
{ {
if (data.size() != Uuid::Length) { if (data.size() != UUID_LENGTH) {
raiseError(tr("Invalid cipher uuid length")); raiseError(tr("Invalid cipher uuid length: %1 (length=%2)").arg(QString(data)).arg(data.size()));
return; return;
} }
Uuid uuid(data); QUuid uuid = QUuid::fromRfc4122(data);
if (uuid.isNull()) {
raiseError(tr("Unable to parse UUID: %1").arg(QString(data)));
return;
}
if (SymmetricCipher::cipherToAlgorithm(uuid) == SymmetricCipher::InvalidAlgorithm) { if (SymmetricCipher::cipherToAlgorithm(uuid) == SymmetricCipher::InvalidAlgorithm) {
raiseError(tr("Unsupported cipher")); raiseError(tr("Unsupported cipher"));

View File

@ -28,6 +28,8 @@
#include <QBuffer> #include <QBuffer>
#include <QFile> #include <QFile>
#define UUID_LENGTH 16
/** /**
* @param version KDBX version * @param version KDBX version
*/ */
@ -142,12 +144,12 @@ void KdbxXmlReader::readDatabase(QIODevice* device, Database* db, KeePass2Random
m_meta->setUpdateDatetime(true); m_meta->setUpdateDatetime(true);
QHash<Uuid, Group*>::const_iterator iGroup; QHash<QUuid, Group*>::const_iterator iGroup;
for (iGroup = m_groups.constBegin(); iGroup != m_groups.constEnd(); ++iGroup) { for (iGroup = m_groups.constBegin(); iGroup != m_groups.constEnd(); ++iGroup) {
iGroup.value()->setUpdateTimeinfo(true); iGroup.value()->setUpdateTimeinfo(true);
} }
QHash<Uuid, Entry*>::const_iterator iEntry; QHash<QUuid, Entry*>::const_iterator iEntry;
for (iEntry = m_entries.constBegin(); iEntry != m_entries.constEnd(); ++iEntry) { for (iEntry = m_entries.constBegin(); iEntry != m_entries.constEnd(); ++iEntry) {
iEntry.value()->setUpdateTimeinfo(true); iEntry.value()->setUpdateTimeinfo(true);
@ -346,7 +348,7 @@ void KdbxXmlReader::parseIcon()
{ {
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Icon"); Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "Icon");
Uuid uuid; QUuid uuid;
QImage icon; QImage icon;
bool uuidSet = false; bool uuidSet = false;
bool iconSet = false; bool iconSet = false;
@ -479,12 +481,12 @@ Group* KdbxXmlReader::parseGroup()
QList<Entry*> entries; QList<Entry*> entries;
while (!m_xml.hasError() && m_xml.readNextStartElement()) { while (!m_xml.hasError() && m_xml.readNextStartElement()) {
if (m_xml.name() == "UUID") { if (m_xml.name() == "UUID") {
Uuid uuid = readUuid(); QUuid uuid = readUuid();
if (uuid.isNull()) { if (uuid.isNull()) {
if (m_strictMode) { if (m_strictMode) {
raiseError(tr("Null group uuid")); raiseError(tr("Null group uuid"));
} else { } else {
group->setUuid(Uuid::random()); group->setUuid(QUuid::createUuid());
} }
} else { } else {
group->setUuid(uuid); group->setUuid(uuid);
@ -515,7 +517,7 @@ Group* KdbxXmlReader::parseGroup()
continue; continue;
} }
if (m_xml.name() == "CustomIconUUID") { if (m_xml.name() == "CustomIconUUID") {
Uuid uuid = readUuid(); QUuid uuid = readUuid();
if (!uuid.isNull()) { if (!uuid.isNull()) {
group->setIcon(uuid); group->setIcon(uuid);
} }
@ -588,7 +590,7 @@ Group* KdbxXmlReader::parseGroup()
} }
if (group->uuid().isNull() && !m_strictMode) { if (group->uuid().isNull() && !m_strictMode) {
group->setUuid(Uuid::random()); group->setUuid(QUuid::createUuid());
} }
if (!group->uuid().isNull()) { if (!group->uuid().isNull()) {
@ -633,10 +635,11 @@ void KdbxXmlReader::parseDeletedObject()
while (!m_xml.hasError() && m_xml.readNextStartElement()) { while (!m_xml.hasError() && m_xml.readNextStartElement()) {
if (m_xml.name() == "UUID") { if (m_xml.name() == "UUID") {
Uuid uuid = readUuid(); QUuid uuid = readUuid();
if (uuid.isNull()) { if (uuid.isNull()) {
if (m_strictMode) { if (m_strictMode) {
raiseError(tr("Null DeleteObject uuid")); raiseError(tr("Null DeleteObject uuid"));
return;
} }
continue; continue;
} }
@ -671,12 +674,12 @@ Entry* KdbxXmlReader::parseEntry(bool history)
while (!m_xml.hasError() && m_xml.readNextStartElement()) { while (!m_xml.hasError() && m_xml.readNextStartElement()) {
if (m_xml.name() == "UUID") { if (m_xml.name() == "UUID") {
Uuid uuid = readUuid(); QUuid uuid = readUuid();
if (uuid.isNull()) { if (uuid.isNull()) {
if (m_strictMode) { if (m_strictMode) {
raiseError(tr("Null entry uuid")); raiseError(tr("Null entry uuid"));
} else { } else {
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
} }
} else { } else {
entry->setUuid(uuid); entry->setUuid(uuid);
@ -695,7 +698,7 @@ Entry* KdbxXmlReader::parseEntry(bool history)
continue; continue;
} }
if (m_xml.name() == "CustomIconUUID") { if (m_xml.name() == "CustomIconUUID") {
Uuid uuid = readUuid(); QUuid uuid = readUuid();
if (!uuid.isNull()) { if (!uuid.isNull()) {
entry->setIcon(uuid); entry->setIcon(uuid);
} }
@ -752,7 +755,7 @@ Entry* KdbxXmlReader::parseEntry(bool history)
} }
if (entry->uuid().isNull() && !m_strictMode) { if (entry->uuid().isNull() && !m_strictMode) {
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
} }
if (!entry->uuid().isNull()) { if (!entry->uuid().isNull()) {
@ -1090,19 +1093,19 @@ int KdbxXmlReader::readNumber()
return result; return result;
} }
Uuid KdbxXmlReader::readUuid() QUuid KdbxXmlReader::readUuid()
{ {
QByteArray uuidBin = readBinary(); QByteArray uuidBin = readBinary();
if (uuidBin.isEmpty()) { if (uuidBin.isEmpty()) {
return {}; return QUuid();
} }
if (uuidBin.length() != Uuid::Length) { if (uuidBin.length() != UUID_LENGTH) {
if (m_strictMode) { if (m_strictMode) {
raiseError(tr("Invalid uuid value")); raiseError(tr("Invalid uuid value"));
} }
return {}; return QUuid();
} }
return Uuid(uuidBin); return QUuid::fromRfc4122(uuidBin);
} }
QByteArray KdbxXmlReader::readBinary() QByteArray KdbxXmlReader::readBinary()
@ -1146,7 +1149,7 @@ QByteArray KdbxXmlReader::readCompressedBinary()
return result; return result;
} }
Group* KdbxXmlReader::getGroup(const Uuid& uuid) Group* KdbxXmlReader::getGroup(const QUuid& uuid)
{ {
if (uuid.isNull()) { if (uuid.isNull()) {
return nullptr; return nullptr;
@ -1164,7 +1167,7 @@ Group* KdbxXmlReader::getGroup(const Uuid& uuid)
return group; return group;
} }
Entry* KdbxXmlReader::getEntry(const Uuid& uuid) Entry* KdbxXmlReader::getEntry(const QUuid& uuid)
{ {
if (uuid.isNull()) { if (uuid.isNull()) {
return nullptr; return nullptr;

View File

@ -21,7 +21,7 @@
#include "core/Database.h" #include "core/Database.h"
#include "core/Metadata.h" #include "core/Metadata.h"
#include "core/TimeInfo.h" #include "core/TimeInfo.h"
#include "core/Uuid.h" #include "core/Database.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QPair> #include <QPair>
@ -86,14 +86,14 @@ protected:
virtual QDateTime readDateTime(); virtual QDateTime readDateTime();
virtual QColor readColor(); virtual QColor readColor();
virtual int readNumber(); virtual int readNumber();
virtual Uuid readUuid(); virtual QUuid readUuid();
virtual QByteArray readBinary(); virtual QByteArray readBinary();
virtual QByteArray readCompressedBinary(); virtual QByteArray readCompressedBinary();
virtual void skipCurrentElement(); virtual void skipCurrentElement();
virtual Group* getGroup(const Uuid& uuid); virtual Group* getGroup(const QUuid& uuid);
virtual Entry* getEntry(const Uuid& uuid); virtual Entry* getEntry(const QUuid& uuid);
virtual bool isTrueValue(const QStringRef& value); virtual bool isTrueValue(const QStringRef& value);
virtual void raiseError(const QString& errorMessage); virtual void raiseError(const QString& errorMessage);
@ -108,8 +108,8 @@ protected:
QXmlStreamReader m_xml; QXmlStreamReader m_xml;
QScopedPointer<Group> m_tmpParent; QScopedPointer<Group> m_tmpParent;
QHash<Uuid, Group*> m_groups; QHash<QUuid, Group*> m_groups;
QHash<Uuid, Entry*> m_entries; QHash<QUuid, Entry*> m_entries;
QHash<QString, QByteArray> m_binaryPool; QHash<QString, QByteArray> m_binaryPool;
QHash<QString, QPair<Entry*, QString>> m_binaryMap; QHash<QString, QPair<Entry*, QString>> m_binaryMap;

View File

@ -154,15 +154,15 @@ void KdbxXmlWriter::writeCustomIcons()
{ {
m_xml.writeStartElement("CustomIcons"); m_xml.writeStartElement("CustomIcons");
const QList<Uuid> customIconsOrder = m_meta->customIconsOrder(); const QList<QUuid> customIconsOrder = m_meta->customIconsOrder();
for (const Uuid& uuid : customIconsOrder) { for (const QUuid& uuid : customIconsOrder) {
writeIcon(uuid, m_meta->customIcon(uuid)); writeIcon(uuid, m_meta->customIcon(uuid));
} }
m_xml.writeEndElement(); m_xml.writeEndElement();
} }
void KdbxXmlWriter::writeIcon(const Uuid& uuid, const QImage& icon) void KdbxXmlWriter::writeIcon(const QUuid& uuid, const QImage& icon)
{ {
m_xml.writeStartElement("Icon"); m_xml.writeStartElement("Icon");
@ -502,9 +502,9 @@ void KdbxXmlWriter::writeDateTime(const QString& qualifiedName, const QDateTime&
writeString(qualifiedName, dateTimeStr); writeString(qualifiedName, dateTimeStr);
} }
void KdbxXmlWriter::writeUuid(const QString& qualifiedName, const Uuid& uuid) void KdbxXmlWriter::writeUuid(const QString& qualifiedName, const QUuid& uuid)
{ {
writeString(qualifiedName, uuid.toBase64()); writeString(qualifiedName, uuid.toRfc4122().toBase64());
} }
void KdbxXmlWriter::writeUuid(const QString& qualifiedName, const Group* group) void KdbxXmlWriter::writeUuid(const QString& qualifiedName, const Group* group)
@ -512,7 +512,7 @@ void KdbxXmlWriter::writeUuid(const QString& qualifiedName, const Group* group)
if (group) { if (group) {
writeUuid(qualifiedName, group->uuid()); writeUuid(qualifiedName, group->uuid());
} else { } else {
writeUuid(qualifiedName, Uuid()); writeUuid(qualifiedName, QUuid());
} }
} }
@ -521,7 +521,7 @@ void KdbxXmlWriter::writeUuid(const QString& qualifiedName, const Entry* entry)
if (entry) { if (entry) {
writeUuid(qualifiedName, entry->uuid()); writeUuid(qualifiedName, entry->uuid());
} else { } else {
writeUuid(qualifiedName, Uuid()); writeUuid(qualifiedName, QUuid());
} }
} }

View File

@ -27,7 +27,6 @@
#include "core/Entry.h" #include "core/Entry.h"
#include "core/Group.h" #include "core/Group.h"
#include "core/TimeInfo.h" #include "core/TimeInfo.h"
#include "core/Uuid.h"
class KeePass2RandomStream; class KeePass2RandomStream;
class Metadata; class Metadata;
@ -51,7 +50,7 @@ private:
void writeMetadata(); void writeMetadata();
void writeMemoryProtection(); void writeMemoryProtection();
void writeCustomIcons(); void writeCustomIcons();
void writeIcon(const Uuid& uuid, const QImage& icon); void writeIcon(const QUuid& uuid, const QImage& icon);
void writeBinaries(); void writeBinaries();
void writeCustomData(const CustomData* customData); void writeCustomData(const CustomData* customData);
void writeCustomDataItem(const QString& key, const QString& value); void writeCustomDataItem(const QString& key, const QString& value);
@ -69,7 +68,7 @@ private:
void writeNumber(const QString& qualifiedName, int number); void writeNumber(const QString& qualifiedName, int number);
void writeBool(const QString& qualifiedName, bool b); void writeBool(const QString& qualifiedName, bool b);
void writeDateTime(const QString& qualifiedName, const QDateTime& dateTime); void writeDateTime(const QString& qualifiedName, const QDateTime& dateTime);
void writeUuid(const QString& qualifiedName, const Uuid& uuid); void writeUuid(const QString& qualifiedName, const QUuid& uuid);
void writeUuid(const QString& qualifiedName, const Group* group); void writeUuid(const QString& qualifiedName, const Group* group);
void writeUuid(const QString& qualifiedName, const Entry* entry); void writeUuid(const QString& qualifiedName, const Entry* entry);
void writeBinary(const QString& qualifiedName, const QByteArray& ba); void writeBinary(const QString& qualifiedName, const QByteArray& ba);

View File

@ -207,7 +207,7 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
} else { } else {
entry->setGroup(m_groupIds.value(groupId)); entry->setGroup(m_groupIds.value(groupId));
} }
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
} }
} }
@ -545,7 +545,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
return nullptr; return nullptr;
} }
group->setUuid(Uuid::random()); group->setUuid(QUuid::createUuid());
group->setTimeInfo(timeInfo); group->setTimeInfo(timeInfo);
m_groupIds.insert(groupId, group.data()); m_groupIds.insert(groupId, group.data());
m_groupLevels.insert(group.data(), groupLevel); m_groupLevels.insert(group.data(), groupLevel);
@ -846,7 +846,7 @@ bool KeePass1Reader::parseCustomIcons4(const QByteArray& data)
quint32 numGroups = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER); quint32 numGroups = Endian::bytesToSizedInt<quint32>(data.mid(pos, 4), KeePass1::BYTEORDER);
pos += 4; pos += 4;
QList<Uuid> iconUuids; QList<QUuid> iconUuids;
for (quint32 i = 0; i < numIcons; i++) { for (quint32 i = 0; i < numIcons; i++) {
if (data.size() < (pos + 4)) { if (data.size() < (pos + 4)) {
@ -865,7 +865,7 @@ bool KeePass1Reader::parseCustomIcons4(const QByteArray& data)
icon = icon.scaled(16, 16); icon = icon.scaled(16, 16);
} }
Uuid uuid = Uuid::random(); QUuid uuid = QUuid::createUuid();
iconUuids.append(uuid); iconUuids.append(uuid);
m_db->metadata()->addCustomIcon(uuid, icon); m_db->metadata()->addCustomIcon(uuid, icon);
} }

View File

@ -21,13 +21,15 @@
#include "crypto/kdf/Argon2Kdf.h" #include "crypto/kdf/Argon2Kdf.h"
#include <QSharedPointer> #include <QSharedPointer>
const Uuid KeePass2::CIPHER_AES = Uuid(QByteArray::fromHex("31c1f2e6bf714350be5805216afc5aff")); #define UUID_LENGTH 16
const Uuid KeePass2::CIPHER_TWOFISH = Uuid(QByteArray::fromHex("ad68f29f576f4bb9a36ad47af965346c"));
const Uuid KeePass2::CIPHER_CHACHA20 = Uuid(QByteArray::fromHex("D6038A2B8B6F4CB5A524339A31DBB59A"));
const Uuid KeePass2::KDF_AES_KDBX3 = Uuid(QByteArray::fromHex("C9D9F39A628A4460BF740D08C18A4FEA")); const QUuid KeePass2::CIPHER_AES = QUuid::fromRfc4122(QByteArray::fromHex("31c1f2e6bf714350be5805216afc5aff"));
const Uuid KeePass2::KDF_AES_KDBX4 = Uuid(QByteArray::fromHex("7C02BB8279A74AC0927D114A00648238")); const QUuid KeePass2::CIPHER_TWOFISH = QUuid::fromRfc4122(QByteArray::fromHex("ad68f29f576f4bb9a36ad47af965346c"));
const Uuid KeePass2::KDF_ARGON2 = Uuid(QByteArray::fromHex("EF636DDF8C29444B91F7A9A403E30A0C")); const QUuid KeePass2::CIPHER_CHACHA20 = QUuid::fromRfc4122(QByteArray::fromHex("D6038A2B8B6F4CB5A524339A31DBB59A"));
const QUuid KeePass2::KDF_AES_KDBX3 = QUuid::fromRfc4122(QByteArray::fromHex("C9D9F39A628A4460BF740D08C18A4FEA"));
const QUuid KeePass2::KDF_AES_KDBX4 = QUuid::fromRfc4122(QByteArray::fromHex("7C02BB8279A74AC0927D114A00648238"));
const QUuid KeePass2::KDF_ARGON2 = QUuid::fromRfc4122(QByteArray::fromHex("EF636DDF8C29444B91F7A9A403E30A0C"));
const QByteArray KeePass2::INNER_STREAM_SALSA20_IV("\xE8\x30\x09\x4B\x97\x20\x5D\x2A"); const QByteArray KeePass2::INNER_STREAM_SALSA20_IV("\xE8\x30\x09\x4B\x97\x20\x5D\x2A");
@ -44,15 +46,17 @@ const QString KeePass2::KDFPARAM_ARGON2_VERSION("V");
const QString KeePass2::KDFPARAM_ARGON2_SECRET("K"); const QString KeePass2::KDFPARAM_ARGON2_SECRET("K");
const QString KeePass2::KDFPARAM_ARGON2_ASSOCDATA("A"); const QString KeePass2::KDFPARAM_ARGON2_ASSOCDATA("A");
const QList<QPair<Uuid, QString>> KeePass2::CIPHERS{ const QList<QPair<QUuid, QString>> KeePass2::CIPHERS{
qMakePair(KeePass2::CIPHER_AES, QString(QT_TRANSLATE_NOOP("KeePass2", "AES: 256-bit"))), qMakePair(KeePass2::CIPHER_AES, QObject::tr("AES: 256-bit")),
qMakePair(KeePass2::CIPHER_TWOFISH, QString(QT_TRANSLATE_NOOP("KeePass2", "Twofish: 256-bit"))), qMakePair(KeePass2::CIPHER_TWOFISH, QObject::tr("Twofish: 256-bit")),
qMakePair(KeePass2::CIPHER_CHACHA20, QString(QT_TRANSLATE_NOOP("KeePass2", "ChaCha20: 256-bit")))}; qMakePair(KeePass2::CIPHER_CHACHA20, QObject::tr("ChaCha20: 256-bit"))
};
const QList<QPair<Uuid, QString>> KeePass2::KDFS{ const QList<QPair<QUuid, QString>> KeePass2::KDFS{
qMakePair(KeePass2::KDF_ARGON2, QString(QT_TRANSLATE_NOOP("KeePass2", "Argon2 (KDBX 4 recommended)"))), qMakePair(KeePass2::KDF_ARGON2, QObject::tr("Argon2 (KDBX 4 recommended)")),
qMakePair(KeePass2::KDF_AES_KDBX4, QString(QT_TRANSLATE_NOOP("KeePass2", "AES-KDF (KDBX 4)"))), qMakePair(KeePass2::KDF_AES_KDBX4, QObject::tr("AES-KDF (KDBX 4)")),
qMakePair(KeePass2::KDF_AES_KDBX3, QString(QT_TRANSLATE_NOOP("KeePass2", "AES-KDF (KDBX 3.1)")))}; qMakePair(KeePass2::KDF_AES_KDBX3, QObject::tr("AES-KDF (KDBX 3.1)"))
};
QByteArray KeePass2::hmacKey(QByteArray masterSeed, QByteArray transformedMasterKey) QByteArray KeePass2::hmacKey(QByteArray masterSeed, QByteArray transformedMasterKey)
{ {
@ -72,11 +76,11 @@ QByteArray KeePass2::hmacKey(QByteArray masterSeed, QByteArray transformedMaster
QSharedPointer<Kdf> KeePass2::kdfFromParameters(const QVariantMap& p) QSharedPointer<Kdf> KeePass2::kdfFromParameters(const QVariantMap& p)
{ {
QByteArray uuidBytes = p.value(KDFPARAM_UUID).toByteArray(); QByteArray uuidBytes = p.value(KDFPARAM_UUID).toByteArray();
if (uuidBytes.size() != Uuid::Length) { if (uuidBytes.size() != UUID_LENGTH) {
return {}; return {};
} }
Uuid kdfUuid(uuidBytes); QUuid kdfUuid = QUuid::fromRfc4122(uuidBytes);
if (kdfUuid == KDF_AES_KDBX3) { if (kdfUuid == KDF_AES_KDBX3) {
// upgrade to non-legacy AES-KDF, since KDBX3 doesn't have any KDF parameters // upgrade to non-legacy AES-KDF, since KDBX3 doesn't have any KDF parameters
kdfUuid = KDF_AES_KDBX4; kdfUuid = KDF_AES_KDBX4;
@ -98,7 +102,7 @@ QVariantMap KeePass2::kdfToParameters(QSharedPointer<Kdf> kdf)
return kdf->writeParameters(); return kdf->writeParameters();
} }
QSharedPointer<Kdf> KeePass2::uuidToKdf(const Uuid& uuid) QSharedPointer<Kdf> KeePass2::uuidToKdf(const QUuid& uuid)
{ {
if (uuid == KDF_AES_KDBX3) { if (uuid == KDF_AES_KDBX3) {
return QSharedPointer<AesKdf>::create(true); return QSharedPointer<AesKdf>::create(true);

View File

@ -23,8 +23,8 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QVariantMap> #include <QVariantMap>
#include <QtGlobal> #include <QtGlobal>
#include <QUuid>
#include "core/Uuid.h"
#include "crypto/SymmetricCipher.h" #include "crypto/SymmetricCipher.h"
#include "crypto/kdf/Kdf.h" #include "crypto/kdf/Kdf.h"
@ -46,13 +46,13 @@ namespace KeePass2
const QSysInfo::Endian BYTEORDER = QSysInfo::LittleEndian; const QSysInfo::Endian BYTEORDER = QSysInfo::LittleEndian;
extern const Uuid CIPHER_AES; extern const QUuid CIPHER_AES;
extern const Uuid CIPHER_TWOFISH; extern const QUuid CIPHER_TWOFISH;
extern const Uuid CIPHER_CHACHA20; extern const QUuid CIPHER_CHACHA20;
extern const Uuid KDF_AES_KDBX3; extern const QUuid KDF_AES_KDBX3;
extern const Uuid KDF_AES_KDBX4; extern const QUuid KDF_AES_KDBX4;
extern const Uuid KDF_ARGON2; extern const QUuid KDF_ARGON2;
extern const QByteArray INNER_STREAM_SALSA20_IV; extern const QByteArray INNER_STREAM_SALSA20_IV;
@ -67,8 +67,8 @@ namespace KeePass2
extern const QString KDFPARAM_ARGON2_SECRET; extern const QString KDFPARAM_ARGON2_SECRET;
extern const QString KDFPARAM_ARGON2_ASSOCDATA; extern const QString KDFPARAM_ARGON2_ASSOCDATA;
extern const QList<QPair<Uuid, QString>> CIPHERS; extern const QList<QPair<QUuid, QString>> CIPHERS;
extern const QList<QPair<Uuid, QString>> KDFS; extern const QList<QPair<QUuid, QString>> KDFS;
enum class HeaderFieldID enum class HeaderFieldID
{ {
@ -125,12 +125,11 @@ namespace KeePass2
ByteArray = 0x42 ByteArray = 0x42
}; };
QByteArray hmacKey(QByteArray masterSeed, QByteArray transformedMasterKey); QByteArray hmacKey(QByteArray masterSeed, QByteArray transformedMasterKey);
QSharedPointer<Kdf> kdfFromParameters(const QVariantMap& p); QSharedPointer<Kdf> kdfFromParameters(const QVariantMap& p);
QVariantMap kdfToParameters(QSharedPointer<Kdf> kdf); QVariantMap kdfToParameters(QSharedPointer<Kdf> kdf);
QSharedPointer<Kdf> uuidToKdf(const Uuid& uuid); QSharedPointer<Kdf> uuidToKdf(const QUuid& uuid);
Uuid kdfToUuid(QSharedPointer<Kdf> kdf); ProtectedStreamAlgo idToProtectedStreamAlgo(quint32 id);
ProtectedStreamAlgo idToProtectedStreamAlgo(quint32 id);
} // namespace KeePass2 } // namespace KeePass2

View File

@ -105,11 +105,10 @@ void DatabaseSettingsWidget::load(Database* db)
} }
m_uiEncryption->algorithmComboBox->clear(); m_uiEncryption->algorithmComboBox->clear();
for (auto& cipher : asConst(KeePass2::CIPHERS)) { for (auto& cipher: asConst(KeePass2::CIPHERS)) {
m_uiEncryption->algorithmComboBox->addItem(QCoreApplication::translate("KeePass2", cipher.second.toUtf8()), m_uiEncryption->algorithmComboBox->addItem(QCoreApplication::translate("KeePass2", cipher.second.toUtf8()), cipher.first);
cipher.first.toByteArray());
} }
int cipherIndex = m_uiEncryption->algorithmComboBox->findData(m_db->cipher().toByteArray()); int cipherIndex = m_uiEncryption->algorithmComboBox->findData(m_db->cipher().toRfc4122());
if (cipherIndex > -1) { if (cipherIndex > -1) {
m_uiEncryption->algorithmComboBox->setCurrentIndex(cipherIndex); m_uiEncryption->algorithmComboBox->setCurrentIndex(cipherIndex);
} }
@ -117,14 +116,13 @@ void DatabaseSettingsWidget::load(Database* db)
// Setup kdf combo box // Setup kdf combo box
m_uiEncryption->kdfComboBox->blockSignals(true); m_uiEncryption->kdfComboBox->blockSignals(true);
m_uiEncryption->kdfComboBox->clear(); m_uiEncryption->kdfComboBox->clear();
for (auto& kdf : asConst(KeePass2::KDFS)) { for (auto& kdf: asConst(KeePass2::KDFS)) {
m_uiEncryption->kdfComboBox->addItem(QCoreApplication::translate("KeePass2", kdf.second.toUtf8()), m_uiEncryption->kdfComboBox->addItem(QCoreApplication::translate("KeePass2", kdf.second.toUtf8()), kdf.first);
kdf.first.toByteArray());
} }
m_uiEncryption->kdfComboBox->blockSignals(false); m_uiEncryption->kdfComboBox->blockSignals(false);
auto kdfUuid = m_db->kdf()->uuid(); auto kdfUuid = m_db->kdf()->uuid();
int kdfIndex = m_uiEncryption->kdfComboBox->findData(kdfUuid.toByteArray()); int kdfIndex = m_uiEncryption->kdfComboBox->findData(kdfUuid);
if (kdfIndex > -1) { if (kdfIndex > -1) {
m_uiEncryption->kdfComboBox->setCurrentIndex(kdfIndex); m_uiEncryption->kdfComboBox->setCurrentIndex(kdfIndex);
kdfChanged(kdfIndex); kdfChanged(kdfIndex);
@ -149,7 +147,7 @@ void DatabaseSettingsWidget::load(Database* db)
void DatabaseSettingsWidget::save() void DatabaseSettingsWidget::save()
{ {
// first perform safety check for KDF rounds // first perform safety check for KDF rounds
auto kdf = KeePass2::uuidToKdf(Uuid(m_uiEncryption->kdfComboBox->currentData().toByteArray())); auto kdf = KeePass2::uuidToKdf(m_uiEncryption->kdfComboBox->currentData().value<QUuid>());
if (kdf->uuid() == KeePass2::KDF_ARGON2 && m_uiEncryption->transformRoundsSpinBox->value() > 10000) { if (kdf->uuid() == KeePass2::KDF_ARGON2 && m_uiEncryption->transformRoundsSpinBox->value() > 10000) {
QMessageBox warning; QMessageBox warning;
warning.setIcon(QMessageBox::Warning); warning.setIcon(QMessageBox::Warning);
@ -218,7 +216,7 @@ void DatabaseSettingsWidget::save()
truncateHistories(); truncateHistories();
} }
m_db->setCipher(Uuid(m_uiEncryption->algorithmComboBox->currentData().toByteArray())); m_db->setCipher(m_uiEncryption->algorithmComboBox->currentData().value<QUuid>());
// Save kdf parameters // Save kdf parameters
kdf->setRounds(m_uiEncryption->transformRoundsSpinBox->value()); kdf->setRounds(m_uiEncryption->transformRoundsSpinBox->value());
@ -256,7 +254,7 @@ void DatabaseSettingsWidget::transformRoundsBenchmark()
m_uiEncryption->transformRoundsSpinBox->setFocus(); m_uiEncryption->transformRoundsSpinBox->setFocus();
// Create a new kdf with the current parameters // Create a new kdf with the current parameters
auto kdf = KeePass2::uuidToKdf(Uuid(m_uiEncryption->kdfComboBox->currentData().toByteArray())); auto kdf = KeePass2::uuidToKdf(m_uiEncryption->kdfComboBox->currentData().value<QUuid>());
kdf->setRounds(m_uiEncryption->transformRoundsSpinBox->value()); kdf->setRounds(m_uiEncryption->transformRoundsSpinBox->value());
if (kdf->uuid() == KeePass2::KDF_ARGON2) { if (kdf->uuid() == KeePass2::KDF_ARGON2) {
auto argon2Kdf = kdf.staticCast<Argon2Kdf>(); auto argon2Kdf = kdf.staticCast<Argon2Kdf>();
@ -286,7 +284,7 @@ void DatabaseSettingsWidget::truncateHistories()
void DatabaseSettingsWidget::kdfChanged(int index) void DatabaseSettingsWidget::kdfChanged(int index)
{ {
Uuid id(m_uiEncryption->kdfComboBox->itemData(index).toByteArray()); QUuid id(m_uiEncryption->kdfComboBox->itemData(index).value<QUuid>());
bool memoryEnabled = id == KeePass2::KDF_ARGON2; bool memoryEnabled = id == KeePass2::KDF_ARGON2;
m_uiEncryption->memoryUsageLabel->setEnabled(memoryEnabled); m_uiEncryption->memoryUsageLabel->setEnabled(memoryEnabled);

View File

@ -369,7 +369,7 @@ void DatabaseWidget::createEntry()
m_newEntry->setTitle(getCurrentSearch()); m_newEntry->setTitle(getCurrentSearch());
endSearch(); endSearch();
} }
m_newEntry->setUuid(Uuid::random()); m_newEntry->setUuid(QUuid::createUuid());
m_newEntry->setUsername(m_db->metadata()->defaultUserName()); m_newEntry->setUsername(m_db->metadata()->defaultUserName());
m_newParent = m_groupView->currentGroup(); m_newParent = m_groupView->currentGroup();
setIconFromParent(); setIconFromParent();
@ -675,7 +675,7 @@ void DatabaseWidget::createGroup()
} }
m_newGroup = new Group(); m_newGroup = new Group();
m_newGroup->setUuid(Uuid::random()); m_newGroup->setUuid(QUuid::createUuid());
m_newParent = m_groupView->currentGroup(); m_newParent = m_groupView->currentGroup();
switchToGroupEdit(m_newGroup, true); switchToGroupEdit(m_newGroup, true);
} }
@ -905,8 +905,8 @@ void DatabaseWidget::unlockDatabase(bool accepted)
replaceDatabase(db); replaceDatabase(db);
restoreGroupEntryFocus(m_groupBeforeLock, m_entryBeforeLock); restoreGroupEntryFocus(m_groupBeforeLock, m_entryBeforeLock);
m_groupBeforeLock = Uuid(); m_groupBeforeLock = QUuid();
m_entryBeforeLock = Uuid(); m_entryBeforeLock = QUuid();
setCurrentWidget(m_mainWidget); setCurrentWidget(m_mainWidget);
m_unlockDatabaseWidget->clearForms(); m_unlockDatabaseWidget->clearForms();
@ -1299,14 +1299,14 @@ void DatabaseWidget::reloadDatabaseFile()
} }
} }
Uuid groupBeforeReload; QUuid groupBeforeReload;
if (m_groupView && m_groupView->currentGroup()) { if (m_groupView && m_groupView->currentGroup()) {
groupBeforeReload = m_groupView->currentGroup()->uuid(); groupBeforeReload = m_groupView->currentGroup()->uuid();
} else { } else {
groupBeforeReload = m_db->rootGroup()->uuid(); groupBeforeReload = m_db->rootGroup()->uuid();
} }
Uuid entryBeforeReload; QUuid entryBeforeReload;
if (m_entryView && m_entryView->currentEntry()) { if (m_entryView && m_entryView->currentEntry()) {
entryBeforeReload = m_entryView->currentEntry()->uuid(); entryBeforeReload = m_entryView->currentEntry()->uuid();
} }
@ -1348,7 +1348,7 @@ QStringList DatabaseWidget::customEntryAttributes() const
* Restores the focus on the group and entry that was focused * Restores the focus on the group and entry that was focused
* before the database was locked or reloaded. * before the database was locked or reloaded.
*/ */
void DatabaseWidget::restoreGroupEntryFocus(Uuid groupUuid, Uuid entryUuid) void DatabaseWidget::restoreGroupEntryFocus(const QUuid& groupUuid, const QUuid& entryUuid)
{ {
Group* restoredGroup = nullptr; Group* restoredGroup = nullptr;
const QList<Group*> groups = m_db->rootGroup()->groupsRecursive(true); const QList<Group*> groups = m_db->rootGroup()->groupsRecursive(true);

View File

@ -24,8 +24,7 @@
#include <QStackedWidget> #include <QStackedWidget>
#include <QTimer> #include <QTimer>
#include "core/Uuid.h" #include "gui/entry/EntryModel.h"
#include "gui/MessageWidget.h" #include "gui/MessageWidget.h"
#include "gui/csvImport/CsvImportWizard.h" #include "gui/csvImport/CsvImportWizard.h"
#include "gui/entry/EntryModel.h" #include "gui/entry/EntryModel.h"
@ -204,7 +203,7 @@ private slots:
// Database autoreload slots // Database autoreload slots
void onWatchedFileChanged(); void onWatchedFileChanged();
void reloadDatabaseFile(); void reloadDatabaseFile();
void restoreGroupEntryFocus(Uuid groupUuid, Uuid EntryUuid); void restoreGroupEntryFocus(const QUuid& groupUuid, const QUuid& EntryUuid);
void unblockAutoReload(); void unblockAutoReload();
private: private:
@ -234,8 +233,8 @@ private:
Entry* m_newEntry; Entry* m_newEntry;
Group* m_newParent; Group* m_newParent;
QString m_filePath; QString m_filePath;
Uuid m_groupBeforeLock; QUuid m_groupBeforeLock;
Uuid m_entryBeforeLock; QUuid m_entryBeforeLock;
MessageWidget* m_messageWidget; MessageWidget* m_messageWidget;
DetailsWidget* m_detailsView; DetailsWidget* m_detailsView;

View File

@ -34,7 +34,7 @@
#endif #endif
IconStruct::IconStruct() IconStruct::IconStruct()
: uuid(Uuid()) : uuid(QUuid())
, number(0) , number(0)
{ {
} }
@ -127,13 +127,10 @@ IconStruct EditWidgetIcons::state()
void EditWidgetIcons::reset() void EditWidgetIcons::reset()
{ {
m_database = nullptr; m_database = nullptr;
m_currentUuid = Uuid(); m_currentUuid = QUuid();
} }
void EditWidgetIcons::load(const Uuid& currentUuid, void EditWidgetIcons::load(const QUuid& currentUuid, Database* database, const IconStruct& iconStruct, const QString& url)
Database* database,
const IconStruct& iconStruct,
const QString& url)
{ {
Q_ASSERT(database); Q_ASSERT(database);
Q_ASSERT(!currentUuid.isNull()); Q_ASSERT(!currentUuid.isNull());
@ -145,7 +142,7 @@ void EditWidgetIcons::load(const Uuid& currentUuid,
m_customIconModel->setIcons(database->metadata()->customIconsScaledPixmaps(), m_customIconModel->setIcons(database->metadata()->customIconsScaledPixmaps(),
database->metadata()->customIconsOrder()); database->metadata()->customIconsOrder());
Uuid iconUuid = iconStruct.uuid; QUuid iconUuid = iconStruct.uuid;
if (iconUuid.isNull()) { if (iconUuid.isNull()) {
int iconNumber = iconStruct.number; int iconNumber = iconStruct.number;
m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(iconNumber, 0)); m_ui->defaultIconsView->setCurrentIndex(m_defaultIconModel->index(iconNumber, 0));
@ -380,9 +377,9 @@ bool EditWidgetIcons::addCustomIcon(const QImage& icon)
scaledicon = icon.scaled(128, 128); scaledicon = icon.scaled(128, 128);
} }
Uuid uuid = m_database->metadata()->findCustomIcon(scaledicon); QUuid uuid = m_database->metadata()->findCustomIcon(scaledicon);
if (uuid.isNull()) { if (uuid.isNull()) {
uuid = Uuid::random(); uuid = QUuid::createUuid();
m_database->metadata()->addCustomIcon(uuid, scaledicon); m_database->metadata()->addCustomIcon(uuid, scaledicon);
m_customIconModel->setIcons(m_database->metadata()->customIconsScaledPixmaps(), m_customIconModel->setIcons(m_database->metadata()->customIconsScaledPixmaps(),
m_database->metadata()->customIconsOrder()); m_database->metadata()->customIconsOrder());
@ -405,7 +402,7 @@ void EditWidgetIcons::removeCustomIcon()
if (m_database) { if (m_database) {
QModelIndex index = m_ui->customIconsView->currentIndex(); QModelIndex index = m_ui->customIconsView->currentIndex();
if (index.isValid()) { if (index.isValid()) {
Uuid iconUuid = m_customIconModel->uuidFromIndex(index); QUuid iconUuid = m_customIconModel->uuidFromIndex(index);
const QList<Entry*> allEntries = m_database->rootGroup()->entriesRecursive(true); const QList<Entry*> allEntries = m_database->rootGroup()->entriesRecursive(true);
QList<Entry*> entriesWithSameIcon; QList<Entry*> entriesWithSameIcon;

View File

@ -24,10 +24,10 @@
#include <QUrl> #include <QUrl>
#include <QWidget> #include <QWidget>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QUuid>
#include "config-keepassx.h" #include "config-keepassx.h"
#include "core/Global.h" #include "core/Global.h"
#include "core/Uuid.h"
#include "gui/MessageWidget.h" #include "gui/MessageWidget.h"
class Database; class Database;
@ -46,7 +46,7 @@ struct IconStruct
{ {
IconStruct(); IconStruct();
Uuid uuid; QUuid uuid;
int number; int number;
}; };
@ -71,7 +71,7 @@ public:
IconStruct state(); IconStruct state();
void reset(); void reset();
void load(const Uuid& currentUuid, Database* database, const IconStruct& iconStruct, const QString& url = ""); void load(const QUuid& currentUuid, Database* database, const IconStruct& iconStruct, const QString& url = "");
public slots: public slots:
void setUrl(const QString& url); void setUrl(const QString& url);
@ -98,7 +98,7 @@ private slots:
private: private:
const QScopedPointer<Ui::EditWidgetIcons> m_ui; const QScopedPointer<Ui::EditWidgetIcons> m_ui;
Database* m_database; Database* m_database;
Uuid m_currentUuid; QUuid m_currentUuid;
#ifdef WITH_XC_NETWORKING #ifdef WITH_XC_NETWORKING
QUrl m_url; QUrl m_url;
QUrl m_fetchUrl; QUrl m_fetchUrl;

View File

@ -16,6 +16,9 @@
*/ */
#include "EditWidgetProperties.h" #include "EditWidgetProperties.h"
#include <QUuid>
#include "MessageBox.h" #include "MessageBox.h"
#include "ui_EditWidgetProperties.h" #include "ui_EditWidgetProperties.h"
@ -39,13 +42,13 @@ EditWidgetProperties::~EditWidgetProperties()
{ {
} }
void EditWidgetProperties::setFields(const TimeInfo& timeInfo, const Uuid& uuid) void EditWidgetProperties::setFields(const TimeInfo& timeInfo, const QUuid& uuid)
{ {
static const QString timeFormat("d MMM yyyy HH:mm:ss"); static const QString timeFormat("d MMM yyyy HH:mm:ss");
m_ui->modifiedEdit->setText(timeInfo.lastModificationTime().toLocalTime().toString(timeFormat)); m_ui->modifiedEdit->setText(timeInfo.lastModificationTime().toLocalTime().toString(timeFormat));
m_ui->createdEdit->setText(timeInfo.creationTime().toLocalTime().toString(timeFormat)); m_ui->createdEdit->setText(timeInfo.creationTime().toLocalTime().toString(timeFormat));
m_ui->accessedEdit->setText(timeInfo.lastAccessTime().toLocalTime().toString(timeFormat)); m_ui->accessedEdit->setText(timeInfo.lastAccessTime().toLocalTime().toString(timeFormat));
m_ui->uuidEdit->setText(uuid.toHex()); m_ui->uuidEdit->setText(uuid.toRfc4122().toHex());
} }
void EditWidgetProperties::setCustomData(const CustomData* customData) void EditWidgetProperties::setCustomData(const CustomData* customData)

View File

@ -25,7 +25,6 @@
#include "core/CustomData.h" #include "core/CustomData.h"
#include "core/TimeInfo.h" #include "core/TimeInfo.h"
#include "core/Uuid.h"
namespace Ui namespace Ui
{ {
@ -40,7 +39,7 @@ public:
explicit EditWidgetProperties(QWidget* parent = nullptr); explicit EditWidgetProperties(QWidget* parent = nullptr);
~EditWidgetProperties(); ~EditWidgetProperties();
void setFields(const TimeInfo& timeInfo, const Uuid& uuid); void setFields(const TimeInfo& timeInfo, const QUuid& uuid);
void setCustomData(const CustomData* customData); void setCustomData(const CustomData* customData);
const CustomData* customData() const; const CustomData* customData() const;

View File

@ -17,6 +17,8 @@
#include "IconModels.h" #include "IconModels.h"
#include <QUuid>
#include "core/DatabaseIcons.h" #include "core/DatabaseIcons.h"
DefaultIconModel::DefaultIconModel(QObject* parent) DefaultIconModel::DefaultIconModel(QObject* parent)
@ -53,7 +55,7 @@ CustomIconModel::CustomIconModel(QObject* parent)
{ {
} }
void CustomIconModel::setIcons(const QHash<Uuid, QPixmap>& icons, const QList<Uuid>& iconsOrder) void CustomIconModel::setIcons(const QHash<QUuid, QPixmap>& icons, const QList<QUuid>& iconsOrder)
{ {
beginResetModel(); beginResetModel();
@ -80,21 +82,21 @@ QVariant CustomIconModel::data(const QModelIndex& index, int role) const
} }
if (role == Qt::DecorationRole) { if (role == Qt::DecorationRole) {
Uuid uuid = uuidFromIndex(index); QUuid uuid = uuidFromIndex(index);
return m_icons.value(uuid); return m_icons.value(uuid);
} }
return QVariant(); return QVariant();
} }
Uuid CustomIconModel::uuidFromIndex(const QModelIndex& index) const QUuid CustomIconModel::uuidFromIndex(const QModelIndex& index) const
{ {
Q_ASSERT(index.isValid()); Q_ASSERT(index.isValid());
return m_iconsOrder.value(index.row()); return m_iconsOrder.value(index.row());
} }
QModelIndex CustomIconModel::indexFromUuid(const Uuid& uuid) const QModelIndex CustomIconModel::indexFromUuid(const QUuid& uuid) const
{ {
int idx = m_iconsOrder.indexOf(uuid); int idx = m_iconsOrder.indexOf(uuid);
if (idx > -1) { if (idx > -1) {

View File

@ -21,8 +21,6 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QPixmap> #include <QPixmap>
#include "core/Uuid.h"
class DefaultIconModel : public QAbstractListModel class DefaultIconModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
@ -43,13 +41,13 @@ public:
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
void setIcons(const QHash<Uuid, QPixmap>& icons, const QList<Uuid>& iconsOrder); void setIcons(const QHash<QUuid, QPixmap>& icons, const QList<QUuid>& iconsOrder);
Uuid uuidFromIndex(const QModelIndex& index) const; QUuid uuidFromIndex(const QModelIndex& index) const;
QModelIndex indexFromUuid(const Uuid& uuid) const; QModelIndex indexFromUuid(const QUuid& uuid) const;
private: private:
QHash<Uuid, QPixmap> m_icons; QHash<QUuid, QPixmap> m_icons;
QList<Uuid> m_iconsOrder; QList<QUuid> m_iconsOrder;
}; };
#endif // KEEPASSX_ICONMODELS_H #endif // KEEPASSX_ICONMODELS_H

View File

@ -203,8 +203,8 @@ void CsvImportWidget::load(const QString& filename, Database* const db)
m_parserModel->setFilename(filename); m_parserModel->setFilename(filename);
m_ui->labelFilename->setText(filename); m_ui->labelFilename->setText(filename);
Group* group = m_db->rootGroup(); Group* group = m_db->rootGroup();
group->setUuid(Uuid::random()); group->setUuid(QUuid::createUuid());
group->setNotes(tr("Imported from CSV file\nOriginal data: %1").arg(filename)); group->setNotes(tr("Imported from CSV file").append("\n").append(tr("Original data: ")) + filename);
parse(); parse();
} }
@ -247,7 +247,7 @@ void CsvImportWidget::writeDatabase()
continue; continue;
} }
Entry* entry = new Entry(); Entry* entry = new Entry();
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
entry->setGroup(splitGroups(m_parserModel->data(m_parserModel->index(r, 0)).toString())); entry->setGroup(splitGroups(m_parserModel->data(m_parserModel->index(r, 0)).toString()));
entry->setTitle(m_parserModel->data(m_parserModel->index(r, 1)).toString()); entry->setTitle(m_parserModel->data(m_parserModel->index(r, 1)).toString());
entry->setUsername(m_parserModel->data(m_parserModel->index(r, 2)).toString()); entry->setUsername(m_parserModel->data(m_parserModel->index(r, 2)).toString());
@ -339,7 +339,7 @@ Group* CsvImportWidget::splitGroups(QString label)
Group* brandNew = new Group(); Group* brandNew = new Group();
brandNew->setParent(current); brandNew->setParent(current);
brandNew->setName(groupName); brandNew->setName(groupName);
brandNew->setUuid(Uuid::random()); brandNew->setUuid(QUuid::createUuid());
current = brandNew; current = brandNew;
} else { } else {
Q_ASSERT(children != nullptr); Q_ASSERT(children != nullptr);

View File

@ -224,8 +224,8 @@ bool GroupModel::dropMimeData(const QMimeData* data,
Group* parentGroup = groupFromIndex(parent); Group* parentGroup = groupFromIndex(parent);
if (isGroup) { if (isGroup) {
Uuid dbUuid; QUuid dbUuid;
Uuid groupUuid; QUuid groupUuid;
stream >> dbUuid >> groupUuid; stream >> dbUuid >> groupUuid;
Database* db = Database::databaseByUuid(dbUuid); Database* db = Database::databaseByUuid(dbUuid);
@ -257,7 +257,7 @@ bool GroupModel::dropMimeData(const QMimeData* data,
Database* targetDb = parentGroup->database(); Database* targetDb = parentGroup->database();
if (sourceDb != targetDb) { if (sourceDb != targetDb) {
QSet<Uuid> customIcons = group->customIconsRecursive(); QSet<QUuid> customIcons = group->customIconsRecursive();
targetDb->metadata()->copyCustomIcons(customIcons, sourceDb->metadata()); targetDb->metadata()->copyCustomIcons(customIcons, sourceDb->metadata());
} }
@ -268,8 +268,8 @@ bool GroupModel::dropMimeData(const QMimeData* data,
} }
while (!stream.atEnd()) { while (!stream.atEnd()) {
Uuid dbUuid; QUuid dbUuid;
Uuid entryUuid; QUuid entryUuid;
stream >> dbUuid >> entryUuid; stream >> dbUuid >> entryUuid;
Database* db = Database::databaseByUuid(dbUuid); Database* db = Database::databaseByUuid(dbUuid);
@ -291,7 +291,7 @@ bool GroupModel::dropMimeData(const QMimeData* data,
Database* sourceDb = dragEntry->group()->database(); Database* sourceDb = dragEntry->group()->database();
Database* targetDb = parentGroup->database(); Database* targetDb = parentGroup->database();
Uuid customIcon = entry->iconUuid(); QUuid customIcon = entry->iconUuid();
if (sourceDb != targetDb && !customIcon.isNull() && !targetDb->metadata()->containsCustomIcon(customIcon)) { if (sourceDb != targetDb && !customIcon.isNull() && !targetDb->metadata()->containsCustomIcon(customIcon)) {
targetDb->metadata()->addCustomIcon(customIcon, sourceDb->metadata()->customIcon(customIcon)); targetDb->metadata()->addCustomIcon(customIcon, sourceDb->metadata()->customIcon(customIcon));

View File

@ -234,11 +234,11 @@ bool SSHAgent::removeIdentity(OpenSSHKey& key)
return true; return true;
} }
void SSHAgent::removeIdentityAtLock(const OpenSSHKey& key, const Uuid& uuid) void SSHAgent::removeIdentityAtLock(const OpenSSHKey& key, const QUuid& uuid)
{ {
OpenSSHKey copy = key; OpenSSHKey copy = key;
copy.clearPrivate(); copy.clearPrivate();
m_keys[uuid.toHex()].insert(copy); m_keys[uuid].insert(copy);
} }
void SSHAgent::databaseModeChanged(DatabaseWidget::Mode mode) void SSHAgent::databaseModeChanged(DatabaseWidget::Mode mode)
@ -249,17 +249,17 @@ void SSHAgent::databaseModeChanged(DatabaseWidget::Mode mode)
return; return;
} }
Uuid uuid = widget->database()->uuid(); const QUuid& uuid = widget->database()->uuid();
if (mode == DatabaseWidget::LockedMode && m_keys.contains(uuid.toHex())) { if (mode == DatabaseWidget::LockedMode && m_keys.contains(uuid)) {
QSet<OpenSSHKey> keys = m_keys.take(uuid.toHex()); QSet<OpenSSHKey> keys = m_keys.take(uuid);
for (OpenSSHKey key : keys) { for (OpenSSHKey key : keys) {
if (!removeIdentity(key)) { if (!removeIdentity(key)) {
emit error(m_error); emit error(m_error);
} }
} }
} else if (mode == DatabaseWidget::ViewMode && !m_keys.contains(uuid.toHex())) { } else if (mode == DatabaseWidget::ViewMode && !m_keys.contains(uuid)) {
for (Entry* e : widget->database()->rootGroup()->entriesRecursive()) { for (Entry* e : widget->database()->rootGroup()->entriesRecursive()) {
if (widget->database()->metadata()->recycleBinEnabled() if (widget->database()->metadata()->recycleBinEnabled()

View File

@ -37,7 +37,7 @@ public:
bool isAgentRunning() const; bool isAgentRunning() const;
bool addIdentity(OpenSSHKey& key, quint32 lifetime = 0, bool confirm = false); bool addIdentity(OpenSSHKey& key, quint32 lifetime = 0, bool confirm = false);
bool removeIdentity(OpenSSHKey& key); bool removeIdentity(OpenSSHKey& key);
void removeIdentityAtLock(const OpenSSHKey& key, const Uuid& uuid); void removeIdentityAtLock(const OpenSSHKey& key, const QUuid& uuid);
signals: signals:
void error(const QString& message); void error(const QString& message);
@ -71,7 +71,7 @@ private:
const quint32 AGENT_COPYDATA_ID = 0x804e50ba; const quint32 AGENT_COPYDATA_ID = 0x804e50ba;
#endif #endif
QMap<QString, QSet<OpenSSHKey>> m_keys; QMap<QUuid, QSet<OpenSSHKey>> m_keys;
QString m_error; QString m_error;
}; };

View File

@ -38,7 +38,7 @@ void TestDeletedObjects::createAndDelete(Database* db, int delObjectsSize)
Group* g = new Group(); Group* g = new Group();
g->setParent(root); g->setParent(root);
Uuid gUuid = Uuid::random(); QUuid gUuid = QUuid::createUuid();
g->setUuid(gUuid); g->setUuid(gUuid);
delete g; delete g;
QCOMPARE(db->deletedObjects().size(), ++delObjectsSize); QCOMPARE(db->deletedObjects().size(), ++delObjectsSize);
@ -47,19 +47,19 @@ void TestDeletedObjects::createAndDelete(Database* db, int delObjectsSize)
Group* g1 = new Group(); Group* g1 = new Group();
g1->setParent(root); g1->setParent(root);
Uuid g1Uuid = Uuid::random(); QUuid g1Uuid = QUuid::createUuid();
g1->setUuid(g1Uuid); g1->setUuid(g1Uuid);
Entry* e1 = new Entry(); Entry* e1 = new Entry();
e1->setGroup(g1); e1->setGroup(g1);
Uuid e1Uuid = Uuid::random(); QUuid e1Uuid = QUuid::createUuid();
e1->setUuid(e1Uuid); e1->setUuid(e1Uuid);
Group* g2 = new Group(); Group* g2 = new Group();
g2->setParent(g1); g2->setParent(g1);
Uuid g2Uuid = Uuid::random(); QUuid g2Uuid = QUuid::createUuid();
g2->setUuid(g2Uuid); g2->setUuid(g2Uuid);
Entry* e2 = new Entry(); Entry* e2 = new Entry();
e2->setGroup(g2); e2->setGroup(g2);
Uuid e2Uuid = Uuid::random(); QUuid e2Uuid = QUuid::createUuid();
e2->setUuid(e2Uuid); e2->setUuid(e2Uuid);
delete g1; delete g1;
@ -74,7 +74,7 @@ void TestDeletedObjects::createAndDelete(Database* db, int delObjectsSize)
Entry* e3 = new Entry(); Entry* e3 = new Entry();
e3->setGroup(root); e3->setGroup(root);
Uuid e3Uuid = Uuid::random(); QUuid e3Uuid = QUuid::createUuid();
e3->setUuid(e3Uuid); e3->setUuid(e3Uuid);
delete e3; delete e3;
@ -132,11 +132,11 @@ void TestDeletedObjects::testDatabaseChange()
Group* g1 = new Group(); Group* g1 = new Group();
g1->setParent(root); g1->setParent(root);
Uuid g1Uuid = Uuid::random(); QUuid g1Uuid = QUuid::createUuid();
g1->setUuid(g1Uuid); g1->setUuid(g1Uuid);
Entry* e1 = new Entry(); Entry* e1 = new Entry();
e1->setGroup(g1); e1->setGroup(g1);
Uuid e1Uuid = Uuid::random(); QUuid e1Uuid = QUuid::createUuid();
e1->setUuid(e1Uuid); e1->setUuid(e1Uuid);
g1->setParent(root2); g1->setParent(root2);

View File

@ -82,7 +82,7 @@ void TestEntry::testCopyDataFrom()
void TestEntry::testClone() void TestEntry::testClone()
{ {
QScopedPointer<Entry> entryOrg(new Entry()); QScopedPointer<Entry> entryOrg(new Entry());
entryOrg->setUuid(Uuid::random()); entryOrg->setUuid(QUuid::createUuid());
entryOrg->setTitle("Original Title"); entryOrg->setTitle("Original Title");
entryOrg->beginUpdate(); entryOrg->beginUpdate();
entryOrg->setTitle("New Title"); entryOrg->setTitle("New Title");
@ -205,7 +205,7 @@ void TestEntry::testResolveRecursivePlaceholders()
auto* entry1 = new Entry(); auto* entry1 = new Entry();
entry1->setGroup(root); entry1->setGroup(root);
entry1->setUuid(Uuid::random()); entry1->setUuid(QUuid::createUuid());
entry1->setTitle("{USERNAME}"); entry1->setTitle("{USERNAME}");
entry1->setUsername("{PASSWORD}"); entry1->setUsername("{PASSWORD}");
entry1->setPassword("{URL}"); entry1->setPassword("{URL}");
@ -215,10 +215,10 @@ void TestEntry::testResolveRecursivePlaceholders()
auto* entry2 = new Entry(); auto* entry2 = new Entry();
entry2->setGroup(root); entry2->setGroup(root);
entry2->setUuid(Uuid::random()); entry2->setUuid(QUuid::createUuid());
entry2->setTitle("Entry2Title"); entry2->setTitle("Entry2Title");
entry2->setUsername("{S:CustomUserNameAttribute}"); entry2->setUsername("{S:CustomUserNameAttribute}");
entry2->setPassword(QString("{REF:P@I:%1}").arg(entry1->uuid().toHex())); entry2->setPassword(QString("{REF:P@I:%1}").arg(QString(entry1->uuid().toRfc4122().toHex())));
entry2->setUrl("http://{S:IpAddress}:{S:Port}/{S:Uri}"); entry2->setUrl("http://{S:IpAddress}:{S:Port}/{S:Uri}");
entry2->attributes()->set("CustomUserNameAttribute", "CustomUserNameValue"); entry2->attributes()->set("CustomUserNameAttribute", "CustomUserNameValue");
entry2->attributes()->set("IpAddress", "127.0.0.1"); entry2->attributes()->set("IpAddress", "127.0.0.1");
@ -227,11 +227,11 @@ void TestEntry::testResolveRecursivePlaceholders()
auto* entry3 = new Entry(); auto* entry3 = new Entry();
entry3->setGroup(root); entry3->setGroup(root);
entry3->setUuid(Uuid::random()); entry3->setUuid(QUuid::createUuid());
entry3->setTitle(QString("{REF:T@I:%1}").arg(entry2->uuid().toHex())); entry3->setTitle(QString("{REF:T@I:%1}").arg(QString(entry2->uuid().toRfc4122().toHex())));
entry3->setUsername(QString("{REF:U@I:%1}").arg(entry2->uuid().toHex())); entry3->setUsername(QString("{REF:U@I:%1}").arg(QString(entry2->uuid().toRfc4122().toHex())));
entry3->setPassword(QString("{REF:P@I:%1}").arg(entry2->uuid().toHex())); entry3->setPassword(QString("{REF:P@I:%1}").arg(QString(entry2->uuid().toRfc4122().toHex())));
entry3->setUrl(QString("{REF:A@I:%1}").arg(entry2->uuid().toHex())); entry3->setUrl(QString("{REF:A@I:%1}").arg(QString(entry2->uuid().toRfc4122().toHex())));
QCOMPARE(entry3->resolveMultiplePlaceholders(entry3->title()), QString("Entry2Title")); QCOMPARE(entry3->resolveMultiplePlaceholders(entry3->title()), QString("Entry2Title"));
QCOMPARE(entry3->resolveMultiplePlaceholders(entry3->username()), QString("CustomUserNameValue")); QCOMPARE(entry3->resolveMultiplePlaceholders(entry3->username()), QString("CustomUserNameValue"));
@ -240,11 +240,11 @@ void TestEntry::testResolveRecursivePlaceholders()
auto* entry4 = new Entry(); auto* entry4 = new Entry();
entry4->setGroup(root); entry4->setGroup(root);
entry4->setUuid(Uuid::random()); entry4->setUuid(QUuid::createUuid());
entry4->setTitle(QString("{REF:T@I:%1}").arg(entry3->uuid().toHex())); entry4->setTitle(QString("{REF:T@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex())));
entry4->setUsername(QString("{REF:U@I:%1}").arg(entry3->uuid().toHex())); entry4->setUsername(QString("{REF:U@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex())));
entry4->setPassword(QString("{REF:P@I:%1}").arg(entry3->uuid().toHex())); entry4->setPassword(QString("{REF:P@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex())));
entry4->setUrl(QString("{REF:A@I:%1}").arg(entry3->uuid().toHex())); entry4->setUrl(QString("{REF:A@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex())));
QCOMPARE(entry4->resolveMultiplePlaceholders(entry4->title()), QString("Entry2Title")); QCOMPARE(entry4->resolveMultiplePlaceholders(entry4->title()), QString("Entry2Title"));
QCOMPARE(entry4->resolveMultiplePlaceholders(entry4->username()), QString("CustomUserNameValue")); QCOMPARE(entry4->resolveMultiplePlaceholders(entry4->username()), QString("CustomUserNameValue"));
@ -253,7 +253,7 @@ void TestEntry::testResolveRecursivePlaceholders()
auto* entry5 = new Entry(); auto* entry5 = new Entry();
entry5->setGroup(root); entry5->setGroup(root);
entry5->setUuid(Uuid::random()); entry5->setUuid(QUuid::createUuid());
entry5->attributes()->set("Scheme", "http"); entry5->attributes()->set("Scheme", "http");
entry5->attributes()->set("Host", "host.org"); entry5->attributes()->set("Host", "host.org");
entry5->attributes()->set("Port", "2017"); entry5->attributes()->set("Port", "2017");
@ -271,8 +271,8 @@ void TestEntry::testResolveRecursivePlaceholders()
auto* entry6 = new Entry(); auto* entry6 = new Entry();
entry6->setGroup(root); entry6->setGroup(root);
entry6->setUuid(Uuid::random()); entry6->setUuid(QUuid::createUuid());
entry6->setTitle(QString("{REF:T@I:%1}").arg(entry3->uuid().toHex())); entry6->setTitle(QString("{REF:T@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex())));
entry6->setUsername(QString("{TITLE}")); entry6->setUsername(QString("{TITLE}"));
entry6->setPassword(QString("{PASSWORD}")); entry6->setPassword(QString("{PASSWORD}"));
@ -282,8 +282,8 @@ void TestEntry::testResolveRecursivePlaceholders()
auto* entry7 = new Entry(); auto* entry7 = new Entry();
entry7->setGroup(root); entry7->setGroup(root);
entry7->setUuid(Uuid::random()); entry7->setUuid(QUuid::createUuid());
entry7->setTitle(QString("{REF:T@I:%1} and something else").arg(entry3->uuid().toHex())); entry7->setTitle(QString("{REF:T@I:%1} and something else").arg(QString(entry3->uuid().toRfc4122().toHex())));
entry7->setUsername(QString("{TITLE}")); entry7->setUsername(QString("{TITLE}"));
entry7->setPassword(QString("PASSWORD")); entry7->setPassword(QString("PASSWORD"));
@ -299,7 +299,7 @@ void TestEntry::testResolveReferencePlaceholders()
auto* entry1 = new Entry(); auto* entry1 = new Entry();
entry1->setGroup(root); entry1->setGroup(root);
entry1->setUuid(Uuid::random()); entry1->setUuid(QUuid::createUuid());
entry1->setTitle("Title1"); entry1->setTitle("Title1");
entry1->setUsername("Username1"); entry1->setUsername("Username1");
entry1->setPassword("Password1"); entry1->setPassword("Password1");
@ -311,7 +311,7 @@ void TestEntry::testResolveReferencePlaceholders()
group->setParent(root); group->setParent(root);
auto* entry2 = new Entry(); auto* entry2 = new Entry();
entry2->setGroup(group); entry2->setGroup(group);
entry2->setUuid(Uuid::random()); entry2->setUuid(QUuid::createUuid());
entry2->setTitle("Title2"); entry2->setTitle("Title2");
entry2->setUsername("Username2"); entry2->setUsername("Username2");
entry2->setPassword("Password2"); entry2->setPassword("Password2");
@ -321,7 +321,7 @@ void TestEntry::testResolveReferencePlaceholders()
auto* entry3 = new Entry(); auto* entry3 = new Entry();
entry3->setGroup(group); entry3->setGroup(group);
entry3->setUuid(Uuid::random()); entry3->setUuid(QUuid::createUuid());
entry3->setTitle("{S:AttributeTitle}"); entry3->setTitle("{S:AttributeTitle}");
entry3->setUsername("{S:AttributeUsername}"); entry3->setUsername("{S:AttributeUsername}");
entry3->setPassword("{S:AttributePassword}"); entry3->setPassword("{S:AttributePassword}");
@ -335,9 +335,9 @@ void TestEntry::testResolveReferencePlaceholders()
auto* tstEntry = new Entry(); auto* tstEntry = new Entry();
tstEntry->setGroup(root); tstEntry->setGroup(root);
tstEntry->setUuid(Uuid::random()); tstEntry->setUuid(QUuid::createUuid());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(entry1->uuid().toHex())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(QString(entry1->uuid().toRfc4122().toHex()))),
entry1->title()); entry1->title());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@T:%1}").arg(entry1->title())), entry1->title()); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@T:%1}").arg(entry1->title())), entry1->title());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@U:%1}").arg(entry1->username())), entry1->title()); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@U:%1}").arg(entry1->username())), entry1->title());
@ -348,7 +348,7 @@ void TestEntry::testResolveReferencePlaceholders()
QString("{REF:T@O:%1}").arg(entry1->attributes()->value("CustomAttribute1"))), QString("{REF:T@O:%1}").arg(entry1->attributes()->value("CustomAttribute1"))),
entry1->title()); entry1->title());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(entry1->uuid().toHex())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(QString(entry1->uuid().toRfc4122().toHex()))),
entry1->title()); entry1->title());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@T:%1}").arg(entry1->title())), entry1->title()); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@T:%1}").arg(entry1->title())), entry1->title());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:U@U:%1}").arg(entry1->username())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:U@U:%1}").arg(entry1->username())),
@ -358,7 +358,7 @@ void TestEntry::testResolveReferencePlaceholders()
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:A@A:%1}").arg(entry1->url())), entry1->url()); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:A@A:%1}").arg(entry1->url())), entry1->url());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:N@N:%1}").arg(entry1->notes())), entry1->notes()); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:N@N:%1}").arg(entry1->notes())), entry1->notes());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(entry2->uuid().toHex())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(QString(entry2->uuid().toRfc4122().toHex()))),
entry2->title()); entry2->title());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@T:%1}").arg(entry2->title())), entry2->title()); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@T:%1}").arg(entry2->title())), entry2->title());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@U:%1}").arg(entry2->username())), entry2->title()); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@U:%1}").arg(entry2->username())), entry2->title());
@ -377,38 +377,23 @@ void TestEntry::testResolveReferencePlaceholders()
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:A@A:%1}").arg(entry2->url())), entry2->url()); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:A@A:%1}").arg(entry2->url())), entry2->url());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:N@N:%1}").arg(entry2->notes())), entry2->notes()); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:N@N:%1}").arg(entry2->notes())), entry2->notes());
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(entry3->uuid().toHex())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex()))), entry3->attributes()->value("AttributeTitle"));
entry3->attributes()->value("AttributeTitle")); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:U@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex()))), entry3->attributes()->value("AttributeUsername"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:U@I:%1}").arg(entry3->uuid().toHex())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:P@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex()))), entry3->attributes()->value("AttributePassword"));
entry3->attributes()->value("AttributeUsername")); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:A@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex()))), entry3->attributes()->value("AttributeUrl"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:P@I:%1}").arg(entry3->uuid().toHex())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:N@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex()))), entry3->attributes()->value("AttributeNotes"));
entry3->attributes()->value("AttributePassword"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:A@I:%1}").arg(entry3->uuid().toHex())),
entry3->attributes()->value("AttributeUrl"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:N@I:%1}").arg(entry3->uuid().toHex())),
entry3->attributes()->value("AttributeNotes"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(entry3->uuid().toHex().toUpper())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:T@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toUpper()))), entry3->attributes()->value("AttributeTitle"));
entry3->attributes()->value("AttributeTitle")); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:U@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toUpper()))), entry3->attributes()->value("AttributeUsername"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:U@I:%1}").arg(entry3->uuid().toHex().toUpper())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:P@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toUpper()))), entry3->attributes()->value("AttributePassword"));
entry3->attributes()->value("AttributeUsername")); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:A@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toUpper()))), entry3->attributes()->value("AttributeUrl"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:P@I:%1}").arg(entry3->uuid().toHex().toUpper())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:N@I:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toUpper()))), entry3->attributes()->value("AttributeNotes"));
entry3->attributes()->value("AttributePassword"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:A@I:%1}").arg(entry3->uuid().toHex().toUpper())),
entry3->attributes()->value("AttributeUrl"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:N@I:%1}").arg(entry3->uuid().toHex().toUpper())),
entry3->attributes()->value("AttributeNotes"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:t@i:%1}").arg(entry3->uuid().toHex().toLower())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:t@i:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toLower()))), entry3->attributes()->value("AttributeTitle"));
entry3->attributes()->value("AttributeTitle")); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:u@i:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toLower()))), entry3->attributes()->value("AttributeUsername"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:u@i:%1}").arg(entry3->uuid().toHex().toLower())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:p@i:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toLower()))), entry3->attributes()->value("AttributePassword"));
entry3->attributes()->value("AttributeUsername")); QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:a@i:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toLower()))), entry3->attributes()->value("AttributeUrl"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:p@i:%1}").arg(entry3->uuid().toHex().toLower())), QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:n@i:%1}").arg(QString(entry3->uuid().toRfc4122().toHex().toLower()))), entry3->attributes()->value("AttributeNotes"));
entry3->attributes()->value("AttributePassword"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:a@i:%1}").arg(entry3->uuid().toHex().toLower())),
entry3->attributes()->value("AttributeUrl"));
QCOMPARE(tstEntry->resolveMultiplePlaceholders(QString("{REF:n@i:%1}").arg(entry3->uuid().toHex().toLower())),
entry3->attributes()->value("AttributeNotes"));
} }
void TestEntry::testResolveNonIdPlaceholdersToUuid() void TestEntry::testResolveNonIdPlaceholdersToUuid()
@ -419,27 +404,27 @@ void TestEntry::testResolveNonIdPlaceholdersToUuid()
auto* referencedEntryTitle = new Entry(); auto* referencedEntryTitle = new Entry();
referencedEntryTitle->setGroup(root); referencedEntryTitle->setGroup(root);
referencedEntryTitle->setTitle("myTitle"); referencedEntryTitle->setTitle("myTitle");
referencedEntryTitle->setUuid(Uuid::random()); referencedEntryTitle->setUuid(QUuid::createUuid());
auto* referencedEntryUsername = new Entry(); auto* referencedEntryUsername = new Entry();
referencedEntryUsername->setGroup(root); referencedEntryUsername->setGroup(root);
referencedEntryUsername->setUsername("myUser"); referencedEntryUsername->setUsername("myUser");
referencedEntryUsername->setUuid(Uuid::random()); referencedEntryUsername->setUuid(QUuid::createUuid());
auto* referencedEntryPassword = new Entry(); auto* referencedEntryPassword = new Entry();
referencedEntryPassword->setGroup(root); referencedEntryPassword->setGroup(root);
referencedEntryPassword->setPassword("myPassword"); referencedEntryPassword->setPassword("myPassword");
referencedEntryPassword->setUuid(Uuid::random()); referencedEntryPassword->setUuid(QUuid::createUuid());
auto* referencedEntryUrl = new Entry(); auto* referencedEntryUrl = new Entry();
referencedEntryUrl->setGroup(root); referencedEntryUrl->setGroup(root);
referencedEntryUrl->setUrl("myUrl"); referencedEntryUrl->setUrl("myUrl");
referencedEntryUrl->setUuid(Uuid::random()); referencedEntryUrl->setUuid(QUuid::createUuid());
auto* referencedEntryNotes = new Entry(); auto* referencedEntryNotes = new Entry();
referencedEntryNotes->setGroup(root); referencedEntryNotes->setGroup(root);
referencedEntryNotes->setNotes("myNotes"); referencedEntryNotes->setNotes("myNotes");
referencedEntryNotes->setUuid(Uuid::random()); referencedEntryNotes->setUuid(QUuid::createUuid());
const QList<QChar> placeholders{'T', 'U', 'P', 'A', 'N'}; const QList<QChar> placeholders{'T', 'U', 'P', 'A', 'N'};
for (const QChar& searchIn : placeholders) { for (const QChar& searchIn : placeholders) {
@ -475,8 +460,9 @@ void TestEntry::testResolveNonIdPlaceholdersToUuid()
newEntry->setGroup(root); newEntry->setGroup(root);
newEntry->setNotes(newEntryNotesRaw); newEntry->setNotes(newEntryNotesRaw);
const QString newEntryNotesResolved = newEntry->resolveMultiplePlaceholders(newEntry->notes()); const QString newEntryNotesResolved =
QCOMPARE(newEntryNotesResolved, QString(referencedEntry->uuid().toHex())); newEntry->resolveMultiplePlaceholders(newEntry->notes());
QCOMPARE(newEntryNotesResolved, QString(referencedEntry->uuid().toRfc4122().toHex()));
} }
} }
@ -487,7 +473,7 @@ void TestEntry::testResolveClonedEntry()
auto* original = new Entry(); auto* original = new Entry();
original->setGroup(root); original->setGroup(root);
original->setUuid(Uuid::random()); original->setUuid(QUuid::createUuid());
original->setTitle("Title"); original->setTitle("Title");
original->setUsername("SomeUsername"); original->setUsername("SomeUsername");
original->setPassword("SomePassword"); original->setPassword("SomePassword");

View File

@ -217,15 +217,14 @@ void TestEntryModel::testCustomIconModel()
QCOMPARE(model->rowCount(), 0); QCOMPARE(model->rowCount(), 0);
QHash<Uuid, QPixmap> icons; QHash<QUuid, QPixmap> icons;
QList<Uuid> iconsOrder; QList<QUuid> iconsOrder;
Uuid iconUuid(QByteArray(16, '2')); QUuid iconUuid = QUuid::fromRfc4122(QByteArray(16, '2'));
icons.insert(iconUuid, QPixmap()); icons.insert(iconUuid, QPixmap());
iconsOrder << iconUuid; iconsOrder << iconUuid;
Uuid iconUuid2(QByteArray(16, '1')); QUuid iconUuid2 = QUuid::fromRfc4122(QByteArray(16, '1'));
QImage icon2;
icons.insert(iconUuid2, QPixmap()); icons.insert(iconUuid2, QPixmap());
iconsOrder << iconUuid2; iconsOrder << iconUuid2;

View File

@ -19,7 +19,6 @@
#define KEEPASSXC_TESTGLOBAL_H #define KEEPASSXC_TESTGLOBAL_H
#include "core/Group.h" #include "core/Group.h"
#include "core/Uuid.h"
#include <QDateTime> #include <QDateTime>
#include <QTest> #include <QTest>
@ -27,14 +26,6 @@
namespace QTest namespace QTest
{ {
template <> inline char* toString(const Uuid& uuid)
{
QByteArray ba = "Uuid(";
ba += uuid.toHex().toLatin1().constData();
ba += ")";
return qstrdup(ba.constData());
}
template <> inline char* toString(const Group::TriState& triState) template <> inline char* toString(const Group::TriState& triState)
{ {
QString value; QString value;

View File

@ -93,7 +93,7 @@ void TestGroup::testParenting()
g4->setName("test"); g4->setName("test");
g3->setName("test"); g3->setName("test");
g1->setName("test"); g1->setName("test");
g3->setIcon(Uuid::random()); g3->setIcon(QUuid::createUuid());
g1->setIcon(2); g1->setIcon(2);
QCOMPARE(spy.count(), 6); QCOMPARE(spy.count(), 6);
delete db; delete db;
@ -293,12 +293,12 @@ void TestGroup::testCopyCustomIcon()
{ {
QScopedPointer<Database> dbSource(new Database()); QScopedPointer<Database> dbSource(new Database());
Uuid groupIconUuid = Uuid::random(); QUuid groupIconUuid = QUuid::createUuid();
QImage groupIcon(16, 16, QImage::Format_RGB32); QImage groupIcon(16, 16, QImage::Format_RGB32);
groupIcon.setPixel(0, 0, qRgb(255, 0, 0)); groupIcon.setPixel(0, 0, qRgb(255, 0, 0));
dbSource->metadata()->addCustomIcon(groupIconUuid, groupIcon); dbSource->metadata()->addCustomIcon(groupIconUuid, groupIcon);
Uuid entryIconUuid = Uuid::random(); QUuid entryIconUuid = QUuid::createUuid();
QImage entryIcon(16, 16, QImage::Format_RGB32); QImage entryIcon(16, 16, QImage::Format_RGB32);
entryIcon.setPixel(0, 0, qRgb(255, 0, 0)); entryIcon.setPixel(0, 0, qRgb(255, 0, 0));
dbSource->metadata()->addCustomIcon(entryIconUuid, entryIcon); dbSource->metadata()->addCustomIcon(entryIconUuid, entryIcon);
@ -412,25 +412,25 @@ void TestGroup::testCopyCustomIcons()
QScopedPointer<Group> group1(new Group()); QScopedPointer<Group> group1(new Group());
group1->setParent(dbSource->rootGroup()); group1->setParent(dbSource->rootGroup());
Uuid group1Icon = Uuid::random(); QUuid group1Icon = QUuid::createUuid();
dbSource->metadata()->addCustomIcon(group1Icon, iconImage1); dbSource->metadata()->addCustomIcon(group1Icon, iconImage1);
group1->setIcon(group1Icon); group1->setIcon(group1Icon);
QScopedPointer<Group> group2(new Group()); QScopedPointer<Group> group2(new Group());
group2->setParent(group1.data()); group2->setParent(group1.data());
Uuid group2Icon = Uuid::random(); QUuid group2Icon = QUuid::createUuid();
dbSource->metadata()->addCustomIcon(group2Icon, iconImage1); dbSource->metadata()->addCustomIcon(group2Icon, iconImage1);
group2->setIcon(group2Icon); group2->setIcon(group2Icon);
QScopedPointer<Entry> entry1(new Entry()); QScopedPointer<Entry> entry1(new Entry());
entry1->setGroup(group2.data()); entry1->setGroup(group2.data());
Uuid entry1IconOld = Uuid::random(); QUuid entry1IconOld = QUuid::createUuid();
dbSource->metadata()->addCustomIcon(entry1IconOld, iconImage1); dbSource->metadata()->addCustomIcon(entry1IconOld, iconImage1);
entry1->setIcon(entry1IconOld); entry1->setIcon(entry1IconOld);
// add history item // add history item
entry1->beginUpdate(); entry1->beginUpdate();
Uuid entry1IconNew = Uuid::random(); QUuid entry1IconNew = QUuid::createUuid();
dbSource->metadata()->addCustomIcon(entry1IconNew, iconImage1); dbSource->metadata()->addCustomIcon(entry1IconNew, iconImage1);
entry1->setIcon(entry1IconNew); entry1->setIcon(entry1IconNew);
entry1->endUpdate(); entry1->endUpdate();
@ -459,7 +459,7 @@ void TestGroup::testFindEntry()
Entry* entry1 = new Entry(); Entry* entry1 = new Entry();
entry1->setTitle(QString("entry1")); entry1->setTitle(QString("entry1"));
entry1->setGroup(db->rootGroup()); entry1->setGroup(db->rootGroup());
entry1->setUuid(Uuid::random()); entry1->setUuid(QUuid::createUuid());
Group* group1 = new Group(); Group* group1 = new Group();
group1->setName("group1"); group1->setName("group1");
@ -468,13 +468,13 @@ void TestGroup::testFindEntry()
entry2->setTitle(QString("entry2")); entry2->setTitle(QString("entry2"));
entry2->setGroup(group1); entry2->setGroup(group1);
entry2->setUuid(Uuid::random()); entry2->setUuid(QUuid::createUuid());
group1->setParent(db->rootGroup()); group1->setParent(db->rootGroup());
Entry* entry; Entry* entry;
entry = db->rootGroup()->findEntry(entry1->uuid().toHex()); entry = db->rootGroup()->findEntry(entry1->uuid().toRfc4122().toHex());
QVERIFY(entry != nullptr); QVERIFY(entry != nullptr);
QCOMPARE(entry->title(), QString("entry1")); QCOMPARE(entry->title(), QString("entry1"));
@ -491,7 +491,7 @@ void TestGroup::testFindEntry()
entry = db->rootGroup()->findEntry(QString("//entry1")); entry = db->rootGroup()->findEntry(QString("//entry1"));
QVERIFY(entry == nullptr); QVERIFY(entry == nullptr);
entry = db->rootGroup()->findEntry(entry2->uuid().toHex()); entry = db->rootGroup()->findEntry(entry2->uuid().toRfc4122().toHex());
QVERIFY(entry != nullptr); QVERIFY(entry != nullptr);
QCOMPARE(entry->title(), QString("entry2")); QCOMPARE(entry->title(), QString("entry2"));
@ -602,7 +602,7 @@ void TestGroup::testPrint()
Entry* entry1 = new Entry(); Entry* entry1 = new Entry();
entry1->setTitle(QString("entry1")); entry1->setTitle(QString("entry1"));
entry1->setGroup(db->rootGroup()); entry1->setGroup(db->rootGroup());
entry1->setUuid(Uuid::random()); entry1->setUuid(QUuid::createUuid());
output = db->rootGroup()->print(); output = db->rootGroup()->print();
QCOMPARE(output, QString("entry1\n")); QCOMPARE(output, QString("entry1\n"));
@ -614,7 +614,7 @@ void TestGroup::testPrint()
entry2->setTitle(QString("entry2")); entry2->setTitle(QString("entry2"));
entry2->setGroup(group1); entry2->setGroup(group1);
entry2->setUuid(Uuid::random()); entry2->setUuid(QUuid::createUuid());
group1->setParent(db->rootGroup()); group1->setParent(db->rootGroup());

View File

@ -71,7 +71,7 @@ void TestKdbx2::testFormat200()
QScopedPointer<Database> db(reader.readDatabase(filename, key)); QScopedPointer<Database> db(reader.readDatabase(filename, key));
QCOMPARE(reader.version(), KeePass2::FILE_VERSION_2 & KeePass2::FILE_VERSION_CRITICAL_MASK); QCOMPARE(reader.version(), KeePass2::FILE_VERSION_2 & KeePass2::FILE_VERSION_CRITICAL_MASK);
QVERIFY(!reader.hasError()); QVERIFY2(!reader.hasError(), reader.errorString().toStdString().c_str());
verifyKdbx2Db(db.data()); verifyKdbx2Db(db.data());
} }
@ -82,6 +82,8 @@ void TestKdbx2::testFormat200Upgrade()
key.addKey(PasswordKey("a")); key.addKey(PasswordKey("a"));
KeePass2Reader reader; KeePass2Reader reader;
QScopedPointer<Database> db(reader.readDatabase(filename, key)); QScopedPointer<Database> db(reader.readDatabase(filename, key));
QVERIFY2(!reader.hasError(), reader.errorString().toStdString().c_str());
QVERIFY(!db.isNull());
QCOMPARE(reader.version(), KeePass2::FILE_VERSION_2 & KeePass2::FILE_VERSION_CRITICAL_MASK); QCOMPARE(reader.version(), KeePass2::FILE_VERSION_2 & KeePass2::FILE_VERSION_CRITICAL_MASK);
QCOMPARE(db->kdf()->uuid(), KeePass2::KDF_AES_KDBX3); QCOMPARE(db->kdf()->uuid(), KeePass2::KDF_AES_KDBX3);

View File

@ -109,7 +109,7 @@ void TestKdbx4::writeKdbx(QIODevice* device, Database* db, bool& hasError, QStri
QCOMPARE(writer.version(), KeePass2::FILE_VERSION_4); QCOMPARE(writer.version(), KeePass2::FILE_VERSION_4);
} }
Q_DECLARE_METATYPE(Uuid); Q_DECLARE_METATYPE(QUuid)
void TestKdbx4::testFormat400() void TestKdbx4::testFormat400()
{ {
QString filename = QString(KEEPASSX_TEST_DATA_DIR).append("/Format400.kdbx"); QString filename = QString(KEEPASSX_TEST_DATA_DIR).append("/Format400.kdbx");
@ -136,8 +136,8 @@ void TestKdbx4::testFormat400()
void TestKdbx4::testFormat400Upgrade() void TestKdbx4::testFormat400Upgrade()
{ {
QFETCH(Uuid, kdfUuid); QFETCH(QUuid, kdfUuid);
QFETCH(Uuid, cipherUuid); QFETCH(QUuid, cipherUuid);
QFETCH(bool, addCustomData); QFETCH(bool, addCustomData);
QFETCH(quint32, expectedVersion); QFETCH(quint32, expectedVersion);
@ -191,8 +191,8 @@ void TestKdbx4::testFormat400Upgrade()
// clang-format off // clang-format off
void TestKdbx4::testFormat400Upgrade_data() void TestKdbx4::testFormat400Upgrade_data()
{ {
QTest::addColumn<Uuid>("kdfUuid"); QTest::addColumn<QUuid>("kdfUuid");
QTest::addColumn<Uuid>("cipherUuid"); QTest::addColumn<QUuid>("cipherUuid");
QTest::addColumn<bool>("addCustomData"); QTest::addColumn<bool>("addCustomData");
QTest::addColumn<quint32>("expectedVersion"); QTest::addColumn<quint32>("expectedVersion");
@ -265,20 +265,20 @@ void TestKdbx4::testUpgradeMasterKeyIntegrity()
} else if (upgradeAction == "group-customdata") { } else if (upgradeAction == "group-customdata") {
auto group = new Group(); auto group = new Group();
group->setParent(db->rootGroup()); group->setParent(db->rootGroup());
group->setUuid(Uuid::random()); group->setUuid(QUuid::createUuid());
group->customData()->set("abc", "def"); group->customData()->set("abc", "def");
} else if (upgradeAction == "rootentry-customdata") { } else if (upgradeAction == "rootentry-customdata") {
auto entry = new Entry(); auto entry = new Entry();
entry->setGroup(db->rootGroup()); entry->setGroup(db->rootGroup());
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
entry->customData()->set("abc", "def"); entry->customData()->set("abc", "def");
} else if (upgradeAction == "entry-customdata") { } else if (upgradeAction == "entry-customdata") {
auto group = new Group(); auto group = new Group();
group->setParent(db->rootGroup()); group->setParent(db->rootGroup());
group->setUuid(Uuid::random()); group->setUuid(QUuid::createUuid());
auto entry = new Entry(); auto entry = new Entry();
entry->setGroup(group); entry->setGroup(group);
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
entry->customData()->set("abc", "def"); entry->customData()->set("abc", "def");
} else { } else {
QFAIL(qPrintable(QString("Unknown action: %s").arg(upgradeAction))); QFAIL(qPrintable(QString("Unknown action: %s").arg(upgradeAction)));
@ -362,14 +362,14 @@ void TestKdbx4::testCustomData()
// test copied custom group data // test copied custom group data
auto* group = new Group(); auto* group = new Group();
group->setParent(root); group->setParent(root);
group->setUuid(Uuid::random()); group->setUuid(QUuid::createUuid());
group->customData()->copyDataFrom(root->customData()); group->customData()->copyDataFrom(root->customData());
QCOMPARE(*group->customData(), *root->customData()); QCOMPARE(*group->customData(), *root->customData());
// test copied custom entry data // test copied custom entry data
auto* entry = new Entry(); auto* entry = new Entry();
entry->setGroup(group); entry->setGroup(group);
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
entry->customData()->copyDataFrom(group->customData()); entry->customData()->copyDataFrom(group->customData());
QCOMPARE(*entry->customData(), *root->customData()); QCOMPARE(*entry->customData(), *root->customData());

View File

@ -47,18 +47,18 @@ void TestKeePass2Format::initTestCase()
m_kdbxSourceDb->setKey(key); m_kdbxSourceDb->setKey(key);
m_kdbxSourceDb->metadata()->setName("TESTDB"); m_kdbxSourceDb->metadata()->setName("TESTDB");
Group* group = m_kdbxSourceDb->rootGroup(); Group* group = m_kdbxSourceDb->rootGroup();
group->setUuid(Uuid::random()); group->setUuid(QUuid::createUuid());
group->setNotes("I'm a note!"); group->setNotes("I'm a note!");
auto entry = new Entry(); auto entry = new Entry();
entry->setPassword(QString::fromUtf8("\xc3\xa4\xa3\xb6\xc3\xbc\xe9\x9b\xbb\xe7\xb4\x85")); entry->setPassword(QString::fromUtf8("\xc3\xa4\xa3\xb6\xc3\xbc\xe9\x9b\xbb\xe7\xb4\x85"));
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
entry->attributes()->set("test", "protectedTest", true); entry->attributes()->set("test", "protectedTest", true);
QVERIFY(entry->attributes()->isProtected("test")); QVERIFY(entry->attributes()->isProtected("test"));
entry->attachments()->set("myattach.txt", QByteArray("this is an attachment")); entry->attachments()->set("myattach.txt", QByteArray("this is an attachment"));
entry->attachments()->set("aaa.txt", QByteArray("also an attachment")); entry->attachments()->set("aaa.txt", QByteArray("also an attachment"));
entry->setGroup(group); entry->setGroup(group);
auto groupNew = new Group(); auto groupNew = new Group();
groupNew->setUuid(Uuid::random()); groupNew->setUuid(QUuid::createUuid());
groupNew->setName("TESTGROUP"); groupNew->setName("TESTGROUP");
groupNew->setNotes("I'm a sub group note!"); groupNew->setNotes("I'm a sub group note!");
groupNew->setParent(group); groupNew->setParent(group);
@ -108,7 +108,7 @@ void TestKeePass2Format::testXmlMetadata()
void TestKeePass2Format::testXmlCustomIcons() void TestKeePass2Format::testXmlCustomIcons()
{ {
QCOMPARE(m_xmlDb->metadata()->customIcons().size(), 1); QCOMPARE(m_xmlDb->metadata()->customIcons().size(), 1);
Uuid uuid = Uuid::fromBase64("++vyI+daLk6omox4a6kQGA=="); QUuid uuid = QUuid::fromRfc4122(QByteArray::fromBase64("++vyI+daLk6omox4a6kQGA=="));
QVERIFY(m_xmlDb->metadata()->customIcons().contains(uuid)); QVERIFY(m_xmlDb->metadata()->customIcons().contains(uuid));
QImage icon = m_xmlDb->metadata()->customIcon(uuid); QImage icon = m_xmlDb->metadata()->customIcon(uuid);
QCOMPARE(icon.width(), 16); QCOMPARE(icon.width(), 16);
@ -128,11 +128,11 @@ void TestKeePass2Format::testXmlGroupRoot()
{ {
const Group* group = m_xmlDb->rootGroup(); const Group* group = m_xmlDb->rootGroup();
QVERIFY(group); QVERIFY(group);
QCOMPARE(group->uuid().toBase64(), QString("lmU+9n0aeESKZvcEze+bRg==")); QCOMPARE(group->uuid(), QUuid::fromRfc4122(QByteArray::fromBase64("lmU+9n0aeESKZvcEze+bRg==")));
QCOMPARE(group->name(), QString("NewDatabase")); QCOMPARE(group->name(), QString("NewDatabase"));
QCOMPARE(group->notes(), QString("")); QCOMPARE(group->notes(), QString(""));
QCOMPARE(group->iconNumber(), 49); QCOMPARE(group->iconNumber(), 49);
QCOMPARE(group->iconUuid(), Uuid()); QCOMPARE(group->iconUuid(), QUuid());
QVERIFY(group->isExpanded()); QVERIFY(group->isExpanded());
TimeInfo ti = group->timeInfo(); TimeInfo ti = group->timeInfo();
QCOMPARE(ti.lastModificationTime(), Test::datetime(2010, 8, 8, 17, 24, 27)); QCOMPARE(ti.lastModificationTime(), Test::datetime(2010, 8, 8, 17, 24, 27));
@ -145,7 +145,7 @@ void TestKeePass2Format::testXmlGroupRoot()
QCOMPARE(group->defaultAutoTypeSequence(), QString("")); QCOMPARE(group->defaultAutoTypeSequence(), QString(""));
QCOMPARE(group->autoTypeEnabled(), Group::Inherit); QCOMPARE(group->autoTypeEnabled(), Group::Inherit);
QCOMPARE(group->searchingEnabled(), Group::Inherit); QCOMPARE(group->searchingEnabled(), Group::Inherit);
QCOMPARE(group->lastTopVisibleEntry()->uuid().toBase64(), QString("+wSUOv6qf0OzW8/ZHAs2sA==")); QCOMPARE(group->lastTopVisibleEntry()->uuid(), QUuid::fromRfc4122(QByteArray::fromBase64("+wSUOv6qf0OzW8/ZHAs2sA==")));
QCOMPARE(group->children().size(), 3); QCOMPARE(group->children().size(), 3);
QVERIFY(m_xmlDb->metadata()->recycleBin() == m_xmlDb->rootGroup()->children().at(2)); QVERIFY(m_xmlDb->metadata()->recycleBin() == m_xmlDb->rootGroup()->children().at(2));
@ -156,11 +156,11 @@ void TestKeePass2Format::testXmlGroup1()
{ {
const Group* group = m_xmlDb->rootGroup()->children().at(0); const Group* group = m_xmlDb->rootGroup()->children().at(0);
QCOMPARE(group->uuid().toBase64(), QString("AaUYVdXsI02h4T1RiAlgtg==")); QCOMPARE(group->uuid(), QUuid::fromRfc4122(QByteArray::fromBase64("AaUYVdXsI02h4T1RiAlgtg==")));
QCOMPARE(group->name(), QString("General")); QCOMPARE(group->name(), QString("General"));
QCOMPARE(group->notes(), QString("Group Notez")); QCOMPARE(group->notes(), QString("Group Notez"));
QCOMPARE(group->iconNumber(), 48); QCOMPARE(group->iconNumber(), 48);
QCOMPARE(group->iconUuid(), Uuid()); QCOMPARE(group->iconUuid(), QUuid());
QCOMPARE(group->isExpanded(), true); QCOMPARE(group->isExpanded(), true);
QCOMPARE(group->defaultAutoTypeSequence(), QString("{Password}{ENTER}")); QCOMPARE(group->defaultAutoTypeSequence(), QString("{Password}{ENTER}"));
QCOMPARE(group->autoTypeEnabled(), Group::Enable); QCOMPARE(group->autoTypeEnabled(), Group::Enable);
@ -172,19 +172,19 @@ void TestKeePass2Format::testXmlGroup2()
{ {
const Group* group = m_xmlDb->rootGroup()->children().at(1); const Group* group = m_xmlDb->rootGroup()->children().at(1);
QCOMPARE(group->uuid().toBase64(), QString("1h4NtL5DK0yVyvaEnN//4A==")); QCOMPARE(group->uuid(), QUuid::fromRfc4122(QByteArray::fromBase64("1h4NtL5DK0yVyvaEnN//4A==")));
QCOMPARE(group->name(), QString("Windows")); QCOMPARE(group->name(), QString("Windows"));
QCOMPARE(group->isExpanded(), false); QCOMPARE(group->isExpanded(), false);
QCOMPARE(group->children().size(), 1); QCOMPARE(group->children().size(), 1);
const Group* child = group->children().first(); const Group* child = group->children().first();
QCOMPARE(child->uuid().toBase64(), QString("HoYE/BjLfUSW257pCHJ/eA==")); QCOMPARE(child->uuid(), QUuid::fromRfc4122(QByteArray::fromBase64("HoYE/BjLfUSW257pCHJ/eA==")));
QCOMPARE(child->name(), QString("Subsub")); QCOMPARE(child->name(), QString("Subsub"));
QCOMPARE(child->entries().size(), 1); QCOMPARE(child->entries().size(), 1);
const Entry* entry = child->entries().first(); const Entry* entry = child->entries().first();
QCOMPARE(entry->uuid().toBase64(), QString("GZpdQvGXOU2kaKRL/IVAGg==")); QCOMPARE(entry->uuid(), QUuid::fromRfc4122(QByteArray::fromBase64("GZpdQvGXOU2kaKRL/IVAGg==")));
QCOMPARE(entry->title(), QString("Subsub Entry")); QCOMPARE(entry->title(), QString("Subsub Entry"));
} }
@ -192,10 +192,10 @@ void TestKeePass2Format::testXmlEntry1()
{ {
const Entry* entry = m_xmlDb->rootGroup()->entries().at(0); const Entry* entry = m_xmlDb->rootGroup()->entries().at(0);
QCOMPARE(entry->uuid().toBase64(), QString("+wSUOv6qf0OzW8/ZHAs2sA==")); QCOMPARE(entry->uuid(), QUuid::fromRfc4122(QByteArray::fromBase64("+wSUOv6qf0OzW8/ZHAs2sA==")));
QCOMPARE(entry->historyItems().size(), 2); QCOMPARE(entry->historyItems().size(), 2);
QCOMPARE(entry->iconNumber(), 0); QCOMPARE(entry->iconNumber(), 0);
QCOMPARE(entry->iconUuid(), Uuid()); QCOMPARE(entry->iconUuid(), QUuid());
QVERIFY(!entry->foregroundColor().isValid()); QVERIFY(!entry->foregroundColor().isValid());
QVERIFY(!entry->backgroundColor().isValid()); QVERIFY(!entry->backgroundColor().isValid());
QCOMPARE(entry->overrideUrl(), QString("")); QCOMPARE(entry->overrideUrl(), QString(""));
@ -254,9 +254,9 @@ void TestKeePass2Format::testXmlEntry2()
{ {
const Entry* entry = m_xmlDb->rootGroup()->entries().at(1); const Entry* entry = m_xmlDb->rootGroup()->entries().at(1);
QCOMPARE(entry->uuid().toBase64(), QString("4jbADG37hkiLh2O0qUdaOQ==")); QCOMPARE(entry->uuid(), QUuid::fromRfc4122(QByteArray::fromBase64("4jbADG37hkiLh2O0qUdaOQ==")));
QCOMPARE(entry->iconNumber(), 0); QCOMPARE(entry->iconNumber(), 0);
QCOMPARE(entry->iconUuid().toBase64(), QString("++vyI+daLk6omox4a6kQGA==")); QCOMPARE(entry->iconUuid(), QUuid::fromRfc4122(QByteArray::fromBase64("++vyI+daLk6omox4a6kQGA==")));
// TODO: test entry->icon() // TODO: test entry->icon()
QCOMPARE(entry->foregroundColor(), QColor(255, 0, 0)); QCOMPARE(entry->foregroundColor(), QColor(255, 0, 0));
QCOMPARE(entry->backgroundColor(), QColor(255, 255, 0)); QCOMPARE(entry->backgroundColor(), QColor(255, 255, 0));
@ -330,11 +330,11 @@ void TestKeePass2Format::testXmlDeletedObjects()
DeletedObject delObj; DeletedObject delObj;
delObj = objList.takeFirst(); delObj = objList.takeFirst();
QCOMPARE(delObj.uuid.toBase64(), QString("5K/bzWCSmkCv5OZxYl4N/w==")); QCOMPARE(delObj.uuid, QUuid::fromRfc4122(QByteArray::fromBase64("5K/bzWCSmkCv5OZxYl4N/w==")));
QCOMPARE(delObj.deletionTime, Test::datetime(2010, 8, 25, 16, 14, 12)); QCOMPARE(delObj.deletionTime, Test::datetime(2010, 8, 25, 16, 14, 12));
delObj = objList.takeFirst(); delObj = objList.takeFirst();
QCOMPARE(delObj.uuid.toBase64(), QString("80h8uSNWgkKhKCp1TgXF7g==")); QCOMPARE(delObj.uuid, QUuid::fromRfc4122(QByteArray::fromBase64("80h8uSNWgkKhKCp1TgXF7g==")));
QCOMPARE(delObj.deletionTime, Test::datetime(2010, 8, 25, 16, 14, 14)); QCOMPARE(delObj.deletionTime, Test::datetime(2010, 8, 25, 16, 14, 14));
QVERIFY(objList.isEmpty()); QVERIFY(objList.isEmpty());
@ -424,7 +424,7 @@ void TestKeePass2Format::testXmlInvalidXmlChars()
QString().append(QChar(0x31)).append(QChar(0xD801)).append(QChar(0xDC37)).append(QChar(0x32)); QString().append(QChar(0x31)).append(QChar(0xD801)).append(QChar(0xDC37)).append(QChar(0x32));
auto entry = new Entry(); auto entry = new Entry();
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
entry->setGroup(dbWrite->rootGroup()); entry->setGroup(dbWrite->rootGroup());
entry->attributes()->set("PlainInvalid", strPlainInvalid); entry->attributes()->set("PlainInvalid", strPlainInvalid);
entry->attributes()->set("PlainValid", strPlainValid); entry->attributes()->set("PlainValid", strPlainValid);
@ -577,12 +577,12 @@ void TestKeePass2Format::testDuplicateAttachments()
auto entry1 = new Entry(); auto entry1 = new Entry();
entry1->setGroup(db->rootGroup()); entry1->setGroup(db->rootGroup());
entry1->setUuid(Uuid("aaaaaaaaaaaaaaaa")); entry1->setUuid(QUuid::fromRfc4122("aaaaaaaaaaaaaaaa"));
entry1->attachments()->set("a", attachment1); entry1->attachments()->set("a", attachment1);
auto entry2 = new Entry(); auto entry2 = new Entry();
entry2->setGroup(db->rootGroup()); entry2->setGroup(db->rootGroup());
entry2->setUuid(Uuid("bbbbbbbbbbbbbbbb")); entry2->setUuid(QUuid::fromRfc4122("bbbbbbbbbbbbbbbb"));
entry2->attachments()->set("b1", attachment1); entry2->attachments()->set("b1", attachment1);
entry2->beginUpdate(); entry2->beginUpdate();
entry2->attachments()->set("b2", attachment1); entry2->attachments()->set("b2", attachment1);
@ -596,7 +596,7 @@ void TestKeePass2Format::testDuplicateAttachments()
auto entry3 = new Entry(); auto entry3 = new Entry();
entry3->setGroup(db->rootGroup()); entry3->setGroup(db->rootGroup());
entry3->setUuid(Uuid("cccccccccccccccc")); entry3->setUuid(QUuid::fromRfc4122("cccccccccccccccc"));
entry3->attachments()->set("c1", attachment2); entry3->attachments()->set("c1", attachment2);
entry3->attachments()->set("c2", attachment2); entry3->attachments()->set("c2", attachment2);
entry3->attachments()->set("c3", attachment3); entry3->attachments()->set("c3", attachment3);

View File

@ -216,8 +216,7 @@ void TestMerge::testResolveConflictKeepBoth()
QVERIFY2(olderEntry->attributes()->hasKey("merged"), "older entry is marked with an attribute \"merged\""); QVERIFY2(olderEntry->attributes()->hasKey("merged"), "older entry is marked with an attribute \"merged\"");
QCOMPARE(olderEntry->historyItems().isEmpty(), false); QCOMPARE(olderEntry->historyItems().isEmpty(), false);
QVERIFY2(olderEntry->uuid().toHex() != updatedEntry->uuid().toHex(), QVERIFY2(olderEntry->uuid() != updatedEntry->uuid(), "KeepBoth should not reuse the UUIDs when cloning.");
"KeepBoth should not reuse the UUIDs when cloning.");
delete dbSource; delete dbSource;
delete dbDestination; delete dbDestination;
@ -308,7 +307,7 @@ void TestMerge::testCreateNewGroups()
QTest::qSleep(1); QTest::qSleep(1);
Group* group3 = new Group(); Group* group3 = new Group();
group3->setName("group3"); group3->setName("group3");
group3->setUuid(Uuid::random()); group3->setUuid(QUuid::createUuid());
group3->setParent(dbSource->rootGroup()); group3->setParent(dbSource->rootGroup());
dbDestination->merge(dbSource); dbDestination->merge(dbSource);
@ -331,7 +330,7 @@ void TestMerge::testMoveEntryIntoNewGroup()
QTest::qSleep(1); QTest::qSleep(1);
Group* group3 = new Group(); Group* group3 = new Group();
group3->setName("group3"); group3->setName("group3");
group3->setUuid(Uuid::random()); group3->setUuid(QUuid::createUuid());
group3->setParent(dbSource->rootGroup()); group3->setParent(dbSource->rootGroup());
Entry* entry1 = dbSource->rootGroup()->findEntry("entry1"); Entry* entry1 = dbSource->rootGroup()->findEntry("entry1");
@ -367,13 +366,13 @@ void TestMerge::testUpdateEntryDifferentLocation()
Group* group3 = new Group(); Group* group3 = new Group();
group3->setName("group3"); group3->setName("group3");
group3->setUuid(Uuid::random()); group3->setUuid(QUuid::createUuid());
group3->setParent(dbDestination->rootGroup()); group3->setParent(dbDestination->rootGroup());
Entry* entry1 = dbDestination->rootGroup()->findEntry("entry1"); Entry* entry1 = dbDestination->rootGroup()->findEntry("entry1");
QVERIFY(entry1 != nullptr); QVERIFY(entry1 != nullptr);
entry1->setGroup(group3); entry1->setGroup(group3);
Uuid uuidBeforeSyncing = entry1->uuid(); QUuid uuidBeforeSyncing = entry1->uuid();
// Change the entry in the source db. // Change the entry in the source db.
QTest::qSleep(1); QTest::qSleep(1);
@ -413,7 +412,7 @@ void TestMerge::testUpdateGroup()
Group* group2 = dbSource->rootGroup()->findChildByName("group2"); Group* group2 = dbSource->rootGroup()->findChildByName("group2");
group2->setName("group2 renamed"); group2->setName("group2 renamed");
group2->setNotes("updated notes"); group2->setNotes("updated notes");
Uuid customIconId = Uuid::random(); QUuid customIconId = QUuid::createUuid();
QImage customIcon; QImage customIcon;
dbSource->metadata()->addCustomIcon(customIconId, customIcon); dbSource->metadata()->addCustomIcon(customIconId, customIcon);
group2->setIcon(customIconId); group2->setIcon(customIconId);
@ -422,7 +421,7 @@ void TestMerge::testUpdateGroup()
QVERIFY(entry1 != nullptr); QVERIFY(entry1 != nullptr);
entry1->setGroup(group2); entry1->setGroup(group2);
entry1->setTitle("entry1 renamed"); entry1->setTitle("entry1 renamed");
Uuid uuidBeforeSyncing = entry1->uuid(); QUuid uuidBeforeSyncing = entry1->uuid();
dbDestination->merge(dbSource); dbDestination->merge(dbSource);
@ -446,7 +445,7 @@ void TestMerge::testUpdateGroupLocation()
{ {
Database* dbDestination = createTestDatabase(); Database* dbDestination = createTestDatabase();
Group* group3 = new Group(); Group* group3 = new Group();
Uuid group3Uuid = Uuid::random(); QUuid group3Uuid = QUuid::createUuid();
group3->setUuid(group3Uuid); group3->setUuid(group3Uuid);
group3->setName("group3"); group3->setName("group3");
group3->setParent(dbDestination->rootGroup()->findChildByName("group1")); group3->setParent(dbDestination->rootGroup()->findChildByName("group1"));
@ -509,7 +508,7 @@ void TestMerge::testMergeCustomIcons()
Database* dbDestination = new Database(); Database* dbDestination = new Database();
Database* dbSource = createTestDatabase(); Database* dbSource = createTestDatabase();
Uuid customIconId = Uuid::random(); QUuid customIconId = QUuid::createUuid();
QImage customIcon; QImage customIcon;
dbSource->metadata()->addCustomIcon(customIconId, customIcon); dbSource->metadata()->addCustomIcon(customIconId, customIcon);
@ -566,11 +565,11 @@ Database* TestMerge::createTestDatabase()
Group* group1 = new Group(); Group* group1 = new Group();
group1->setName("group1"); group1->setName("group1");
group1->setUuid(Uuid::random()); group1->setUuid(QUuid::createUuid());
Group* group2 = new Group(); Group* group2 = new Group();
group2->setName("group2"); group2->setName("group2");
group2->setUuid(Uuid::random()); group2->setUuid(QUuid::createUuid());
Entry* entry1 = new Entry(); Entry* entry1 = new Entry();
Entry* entry2 = new Entry(); Entry* entry2 = new Entry();
@ -578,14 +577,14 @@ Database* TestMerge::createTestDatabase()
// Give Entry 1 a history // Give Entry 1 a history
entry1->beginUpdate(); entry1->beginUpdate();
entry1->setGroup(group1); entry1->setGroup(group1);
entry1->setUuid(Uuid::random()); entry1->setUuid(QUuid::createUuid());
entry1->setTitle("entry1"); entry1->setTitle("entry1");
entry1->endUpdate(); entry1->endUpdate();
// Give Entry 2 a history // Give Entry 2 a history
entry2->beginUpdate(); entry2->beginUpdate();
entry2->setGroup(group1); entry2->setGroup(group1);
entry2->setUuid(Uuid::random()); entry2->setUuid(QUuid::createUuid());
entry2->setTitle("entry2"); entry2->setTitle("entry2");
entry2->endUpdate(); entry2->endUpdate();

View File

@ -115,7 +115,7 @@ void TestModified::testGroupSets()
QSignalSpy spyModified(db.data(), SIGNAL(modifiedImmediate())); QSignalSpy spyModified(db.data(), SIGNAL(modifiedImmediate()));
root->setUuid(Uuid::random()); root->setUuid(QUuid::createUuid());
QCOMPARE(spyModified.count(), ++spyCount); QCOMPARE(spyModified.count(), ++spyCount);
root->setUuid(root->uuid()); root->setUuid(root->uuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
@ -135,12 +135,13 @@ void TestModified::testGroupSets()
root->setIcon(root->iconNumber()); root->setIcon(root->iconNumber());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
root->setIcon(Uuid::random()); root->setIcon(QUuid::createUuid());
QCOMPARE(spyModified.count(), ++spyCount); QCOMPARE(spyModified.count(), ++spyCount);
root->setIcon(root->iconUuid()); root->setIcon(root->iconUuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
group->setUuid(Uuid::random());
group->setUuid(QUuid::createUuid());
QCOMPARE(spyModified.count(), ++spyCount); QCOMPARE(spyModified.count(), ++spyCount);
group->setUuid(group->uuid()); group->setUuid(group->uuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
@ -160,7 +161,7 @@ void TestModified::testGroupSets()
group->setIcon(group->iconNumber()); group->setIcon(group->iconNumber());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
group->setIcon(Uuid::random()); group->setIcon(QUuid::createUuid());
QCOMPARE(spyModified.count(), ++spyCount); QCOMPARE(spyModified.count(), ++spyCount);
group->setIcon(group->iconUuid()); group->setIcon(group->iconUuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
@ -179,7 +180,7 @@ void TestModified::testEntrySets()
QSignalSpy spyModified(db.data(), SIGNAL(modifiedImmediate())); QSignalSpy spyModified(db.data(), SIGNAL(modifiedImmediate()));
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
QCOMPARE(spyModified.count(), ++spyCount); QCOMPARE(spyModified.count(), ++spyCount);
entry->setUuid(entry->uuid()); entry->setUuid(entry->uuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
@ -214,7 +215,7 @@ void TestModified::testEntrySets()
entry->setIcon(entry->iconNumber()); entry->setIcon(entry->iconNumber());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
entry->setIcon(Uuid::random()); entry->setIcon(QUuid::createUuid());
QCOMPARE(spyModified.count(), ++spyCount); QCOMPARE(spyModified.count(), ++spyCount);
entry->setIcon(entry->iconUuid()); entry->setIcon(entry->iconUuid());
QCOMPARE(spyModified.count(), spyCount); QCOMPARE(spyModified.count(), spyCount);
@ -283,7 +284,7 @@ void TestModified::testHistoryItems()
{ {
QScopedPointer<Entry> entry(new Entry()); QScopedPointer<Entry> entry(new Entry());
QDateTime created = entry->timeInfo().creationTime(); QDateTime created = entry->timeInfo().creationTime();
entry->setUuid(Uuid::random()); entry->setUuid(QUuid::createUuid());
entry->setTitle("a"); entry->setTitle("a");
entry->setTags("a"); entry->setTags("a");
QScopedPointer<EntryAttributes> attributes(new EntryAttributes()); QScopedPointer<EntryAttributes> attributes(new EntryAttributes());

View File

@ -73,7 +73,7 @@ void TestGuiPixmaps::testEntryIcons()
QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey()); QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey());
QCOMPARE(pixmapCached2.cacheKey(), pixmap.cacheKey()); QCOMPARE(pixmapCached2.cacheKey(), pixmap.cacheKey());
Uuid iconUuid = Uuid::random(); QUuid iconUuid = QUuid::createUuid();
icon = QImage(2, 1, QImage::Format_RGB32); icon = QImage(2, 1, QImage::Format_RGB32);
icon.setPixel(0, 0, qRgb(0, 0, 0)); icon.setPixel(0, 0, qRgb(0, 0, 0));
icon.setPixel(1, 0, qRgb(0, 0, 50)); icon.setPixel(1, 0, qRgb(0, 0, 50));
@ -116,7 +116,7 @@ void TestGuiPixmaps::testGroupIcons()
QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey()); QCOMPARE(pixmapCached1.cacheKey(), pixmap.cacheKey());
QCOMPARE(pixmapCached2.cacheKey(), pixmap.cacheKey()); QCOMPARE(pixmapCached2.cacheKey(), pixmap.cacheKey());
Uuid iconUuid = Uuid::random(); QUuid iconUuid = QUuid::createUuid();
icon = QImage(2, 1, QImage::Format_RGB32); icon = QImage(2, 1, QImage::Format_RGB32);
icon.setPixel(0, 0, qRgb(0, 0, 0)); icon.setPixel(0, 0, qRgb(0, 0, 0));
icon.setPixel(1, 0, qRgb(0, 0, 50)); icon.setPixel(1, 0, qRgb(0, 0, 50));