squawk/core/handlers/trusthandler.h

82 lines
3.2 KiB
C++

// Squawk messenger.
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
//
// 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 3 of the License, or
// (at your option) any later version.
//
// 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 CORE_TRUSTHANDLER_H
#define CORE_TRUSTHANDLER_H
#include <shared/enums.h>
#include <QXmppTrustStorage.h>
#include <cache.h>
namespace Core {
class Account;
class TrustHandler : public QXmppTrustStorage {
public:
TrustHandler(Account* account);
~TrustHandler();
typedef QMultiHash<QString, QByteArray> MultySB;
typedef QHash<QString, MultySB> HashSM;
typedef const QList<QString>& CLSR;
typedef const QList<QByteArray>& CLBAR;
typedef const QString& CSR;
typedef QXmpp::TrustLevel TL;
typedef QHash<QString, QHash<QByteArray, TL>> HSHBTL;
typedef std::map<QByteArray, Shared::TrustLevel> Keys;
typedef DataBase::Cache<QString, Keys> KeyCache;
virtual QFuture<void> resetAll(CSR encryption);
virtual QFuture<TL> trustLevel(CSR encryption, CSR keyOwnerJid, const QByteArray& keyId);
virtual QFuture<HashSM> setTrustLevel(CSR encryption, CLSR keyOwnerJids, TL oldTrustLevel, TL newTrustLevel);
virtual QFuture<HashSM> setTrustLevel(CSR encryption, const MultySB& keyIds, TL trustLevel);
virtual QFuture<bool> hasKey(CSR encryption, CSR keyOwnerJid, QXmpp::TrustLevels trustLevels);
virtual QFuture<HSHBTL> keys(CSR encryption, CLSR keyOwnerJids, QXmpp::TrustLevels trustLevels);
virtual QFuture<QHash<TL, MultySB>> keys(CSR encryption, QXmpp::TrustLevels trustLevels);
virtual QFuture<void> removeKeys(CSR encryption);
virtual QFuture<void> removeKeys(CSR encryption, CSR keyOwnerJid);
virtual QFuture<void> removeKeys(CSR encryption, CLBAR keyIds);
virtual QFuture<void> addKeys(CSR encryption, CSR keyOwnerJid, CLBAR keyIds, TL trustLevel);
virtual QFuture<QByteArray> ownKey(CSR encryption);
virtual QFuture<void> resetOwnKey(CSR encryption);
virtual QFuture<void> setOwnKey(CSR encryption, const QByteArray& keyId);
virtual QFuture<QXmpp::TrustSecurityPolicy> securityPolicy(CSR encryption);
virtual QFuture<void> resetSecurityPolicy(CSR encryption);
virtual QFuture<void> setSecurityPolicy(CSR encryption, QXmpp::TrustSecurityPolicy securityPolicy);
static TL convert(Shared::TrustLevel level);
static Shared::TrustLevel convert(TL level);
private:
static QFuture<void> emptyVoidFuture();
KeyCache* createNewCache(const QString& encryption);
KeyCache* getCache(const QString& encryption);
private:
Account* acc;
DataBase db;
QFile protocols;
DataBase::Cache<QString, uint8_t>* securityPolicies;
DataBase::Cache<QString, QByteArray>* ownKeys;
std::map<QString, KeyCache*> keysByProtocol;
};
}
#endif // CORE_TRUSTHANDLER_H