forked from blue/squawk
showing the button for encryption if there is at least one omemo key, trust summary update calculations
This commit is contained in:
parent
4f295fee3c
commit
69d797fe51
9 changed files with 134 additions and 39 deletions
|
@ -79,7 +79,25 @@ Core::TrustHandler::KeyCache * Core::TrustHandler::createNewCache(const QString&
|
|||
QXmppTask<void> Core::TrustHandler::resetAll(const QString& encryption) {
|
||||
securityPolicies->removeRecord(encryption);
|
||||
ownKeys->removeRecord(encryption);
|
||||
getCache(encryption)->drop();
|
||||
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(encryption);
|
||||
if (itr == keysByProtocol.end())
|
||||
return Core::makeReadyTask();
|
||||
|
||||
KeyCache* cache = itr->second;
|
||||
std::map<QString, Keys> keys = cache->readAll();
|
||||
cache->drop();
|
||||
|
||||
for (const std::pair<const QString, Keys>& pair : keys) {
|
||||
bool empty = true;
|
||||
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : pair.second) {
|
||||
if (trust.second != Shared::TrustLevel::undecided) {
|
||||
empty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!empty)
|
||||
emit trustLevelsChanged(pair.first, getSummary(pair.first));
|
||||
}
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
@ -109,6 +127,7 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys;
|
||||
Shared::TrustLevel oldLevel = convert(oldTrustLevel);
|
||||
Shared::TrustLevel newLevel = convert(newTrustLevel);
|
||||
std::set<QString> modifiedJids;
|
||||
KeyCache* cache = getCache(encryption);
|
||||
for (const QString& keyOwnerJid : keyOwnerJids) {
|
||||
Keys map = cache->getRecord(keyOwnerJid);
|
||||
|
@ -118,13 +137,16 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
if (current == oldLevel) {
|
||||
current = newLevel;
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, pair.first);
|
||||
modifiedJids.insert(keyOwnerJid);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
if (count > 0)
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
}
|
||||
}
|
||||
for (const QString& jid : modifiedJids)
|
||||
emit trustLevelsChanged(jid, getSummary(jid));
|
||||
|
||||
return Core::makeReadyTask(std::move(modifiedKeys));
|
||||
}
|
||||
|
||||
|
@ -135,6 +157,7 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
{
|
||||
QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys;
|
||||
Shared::TrustLevel level = convert(trustLevel);
|
||||
std::set<QString> modifiedJids;
|
||||
KeyCache* cache = getCache(encryption);
|
||||
|
||||
for (MultySB::const_iterator itr = keyIds.begin(), end = keyIds.end(); itr != end; ++itr) {
|
||||
|
@ -150,14 +173,20 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
}
|
||||
if (changed) {
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
modifiedJids.insert(keyOwnerJid);
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
}
|
||||
} catch (const DataBase::NotFound& e) {
|
||||
Keys map({{keyId, level}});
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
modifiedJids.insert(keyOwnerJid);
|
||||
cache->addRecord(keyOwnerJid, map);
|
||||
}
|
||||
}
|
||||
|
||||
for (const QString& jid : modifiedJids)
|
||||
emit trustLevelsChanged(jid, getSummary(jid));
|
||||
|
||||
return Core::makeReadyTask(std::move(modifiedKeys));
|
||||
}
|
||||
|
||||
|
@ -220,12 +249,41 @@ QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> Core::Trust
|
|||
}
|
||||
|
||||
QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption) {
|
||||
getCache(encryption)->drop();
|
||||
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(encryption);
|
||||
if (itr == keysByProtocol.end())
|
||||
return Core::makeReadyTask();
|
||||
|
||||
KeyCache* cache = itr->second;
|
||||
std::map<QString, Keys> keys = cache->readAll();
|
||||
cache->drop();
|
||||
|
||||
for (const std::pair<const QString, Keys>& pair : keys) {
|
||||
bool empty = true;
|
||||
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : pair.second) {
|
||||
if (trust.second != Shared::TrustLevel::undecided) {
|
||||
empty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!empty)
|
||||
emit trustLevelsChanged(pair.first, getSummary(pair.first));
|
||||
}
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) {
|
||||
getCache(encryption)->removeRecord(keyOwnerJid);
|
||||
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(encryption);
|
||||
if (itr == keysByProtocol.end())
|
||||
return Core::makeReadyTask();
|
||||
|
||||
KeyCache* cache = itr->second;
|
||||
try {
|
||||
cache->removeRecord(keyOwnerJid);
|
||||
emit trustLevelsChanged(keyOwnerJid, getSummary(keyOwnerJid)); //TODO there is a probability of notification without the actial change
|
||||
} catch (const DataBase::NotFound& e) {} //if the movin entry was empty or if it consisted of Undecided keys
|
||||
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
|
@ -236,14 +294,15 @@ QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const
|
|||
|
||||
KeyCache* cache = getCache(encryption);
|
||||
std::map<QString, Keys> data = cache->readAll();
|
||||
bool changed = false;
|
||||
std::set<QString> modifiedJids;
|
||||
|
||||
for (std::map<QString, Keys>::iterator cItr = data.begin(), cEnd = data.end(); cItr != cEnd; /*no increment*/) {
|
||||
Keys& byOwner = cItr->second;
|
||||
for (Keys::const_iterator itr = byOwner.begin(), end = byOwner.end(); itr != end; /*no increment*/) {
|
||||
const QByteArray& keyId = itr->first;
|
||||
if (set.erase(keyId)) {
|
||||
byOwner.erase(itr++);
|
||||
changed = true;
|
||||
modifiedJids.insert(cItr->first);
|
||||
} else
|
||||
++itr;
|
||||
}
|
||||
|
@ -252,8 +311,12 @@ QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const
|
|||
else
|
||||
++cItr;
|
||||
}
|
||||
if (changed)
|
||||
if (modifiedJids.size() > 0) {
|
||||
cache->replaceAll(data);
|
||||
}
|
||||
|
||||
for (const QString& jid : modifiedJids)
|
||||
emit trustLevelsChanged(jid, getSummary(jid));
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
@ -278,11 +341,12 @@ QXmppTask<void> Core::TrustHandler::addKeys(
|
|||
result.first->second = level;
|
||||
}
|
||||
|
||||
if (had) {
|
||||
if (had)
|
||||
cache->changeRecord(keyOwnerJid, data);
|
||||
} else {
|
||||
else
|
||||
cache->addRecord(keyOwnerJid, data);
|
||||
}
|
||||
|
||||
emit trustLevelsChanged(keyOwnerJid, getSummary(keyOwnerJid));
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue