From 4c565dd7dd78340a393ccbf4bc3bed9f6ce360f2 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Tue, 19 Apr 2022 20:05:16 +0200 Subject: Add QXmppTrustManager as base of trust managers such as QXmppAtmManager --- src/client/QXmppTrustMemoryStorage.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/client/QXmppTrustMemoryStorage.cpp') diff --git a/src/client/QXmppTrustMemoryStorage.cpp b/src/client/QXmppTrustMemoryStorage.cpp index c9e2f37f..a94768d2 100644 --- a/src/client/QXmppTrustMemoryStorage.cpp +++ b/src/client/QXmppTrustMemoryStorage.cpp @@ -50,7 +50,7 @@ QXmppTrustMemoryStorage::QXmppTrustMemoryStorage() QXmppTrustMemoryStorage::~QXmppTrustMemoryStorage() = default; /// \cond -QFuture QXmppTrustMemoryStorage::setSecurityPolicy(const QString &encryption, const QXmppTrustStorage::SecurityPolicy securityPolicy) +QFuture QXmppTrustMemoryStorage::setSecurityPolicy(const QString &encryption, QXmppTrustStorage::SecurityPolicy securityPolicy) { d->securityPolicies.insert(encryption, securityPolicy); return makeReadyFuture(); @@ -85,7 +85,7 @@ QFuture QXmppTrustMemoryStorage::ownKey(const QString &encryption) return makeReadyFuture(std::move(key)); } -QFuture QXmppTrustMemoryStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, const QXmppTrustStorage::TrustLevel trustLevel) +QFuture QXmppTrustMemoryStorage::addKeys(const QString &encryption, const QString &keyOwnerJid, const QList &keyIds, QXmppTrustStorage::TrustLevel trustLevel) { for (const auto &keyId : keyIds) { Key key; @@ -132,7 +132,7 @@ QFuture QXmppTrustMemoryStorage::removeKeys(const QString &encryption) return makeReadyFuture(); } -QFuture>> QXmppTrustMemoryStorage::keys(const QString &encryption, const TrustLevels trustLevels) +QFuture>> QXmppTrustMemoryStorage::keys(const QString &encryption, TrustLevels trustLevels) { QHash> keys; @@ -175,8 +175,10 @@ QFuture QXmppTrustMemoryStorage::hasKey(const QString &encryption, const Q return makeReadyFuture(std::move(false)); } -QFuture QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, const QMultiHash &keyIds, const TrustLevel trustLevel) +QFuture>> QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, const QMultiHash &keyIds, TrustLevel trustLevel) { + QHash> modifiedKeys; + for (auto itr = keyIds.constBegin(); itr != keyIds.constEnd(); ++itr) { const auto keyOwnerJid = itr.key(); const auto keyId = itr.value(); @@ -191,6 +193,7 @@ QFuture QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, // Update the stored trust level if it differs from the new one. if (key.trustLevel != trustLevel) { key.trustLevel = trustLevel; + modifiedKeys[encryption].insert(keyOwnerJid, keyId); } isKeyFound = true; @@ -205,22 +208,27 @@ QFuture QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, key.ownerJid = keyOwnerJid; key.trustLevel = trustLevel; d->keys.insert(encryption, key); + modifiedKeys[encryption].insert(keyOwnerJid, keyId); } } - return makeReadyFuture(); + return makeReadyFuture(std::move(modifiedKeys)); } -QFuture QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, const QList &keyOwnerJids, const QXmppTrustStorage::TrustLevel oldTrustLevel, const QXmppTrustStorage::TrustLevel newTrustLevel) +QFuture>> QXmppTrustMemoryStorage::setTrustLevel(const QString &encryption, const QList &keyOwnerJids, TrustLevel oldTrustLevel, TrustLevel newTrustLevel) { + QHash> modifiedKeys; + for (auto itr = d->keys.find(encryption); itr != d->keys.end() && itr.key() == encryption; ++itr) { auto &key = itr.value(); - if (keyOwnerJids.contains(key.ownerJid) && key.trustLevel == oldTrustLevel) { + auto keyOwnerJid = key.ownerJid; + if (keyOwnerJids.contains(keyOwnerJid) && key.trustLevel == oldTrustLevel) { key.trustLevel = newTrustLevel; + modifiedKeys[encryption].insert(keyOwnerJid, key.id); } } - return makeReadyFuture(); + return makeReadyFuture(std::move(modifiedKeys)); } QFuture QXmppTrustMemoryStorage::trustLevel(const QString &encryption, const QString &keyOwnerJid, const QByteArray &keyId) @@ -228,7 +236,7 @@ QFuture QXmppTrustMemoryStorage::trustLevel(const const auto keys = d->keys.values(encryption); for (const auto &key : keys) { if (key.id == keyId && key.ownerJid == keyOwnerJid) { - return makeReadyFuture(std::move(QXmppTrustStorage::TrustLevel(key.trustLevel))); + return makeReadyFuture(std::move(TrustLevel(key.trustLevel))); } } -- cgit v1.2.3