81 lines
3.2 KiB
C++
81 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 QXmppTask<void> resetAll(CSR encryption);
|
|
virtual QXmppTask<TL> trustLevel(CSR encryption, CSR keyOwnerJid, const QByteArray& keyId);
|
|
virtual QXmppTask<HashSM> setTrustLevel(CSR encryption, CLSR keyOwnerJids, TL oldTrustLevel, TL newTrustLevel);
|
|
virtual QXmppTask<HashSM> setTrustLevel(CSR encryption, const MultySB& keyIds, TL trustLevel);
|
|
virtual QXmppTask<bool> hasKey(CSR encryption, CSR keyOwnerJid, QXmpp::TrustLevels trustLevels);
|
|
virtual QXmppTask<HSHBTL> keys(CSR encryption, CLSR keyOwnerJids, QXmpp::TrustLevels trustLevels);
|
|
virtual QXmppTask<QHash<TL, MultySB>> keys(CSR encryption, QXmpp::TrustLevels trustLevels);
|
|
virtual QXmppTask<void> removeKeys(CSR encryption);
|
|
virtual QXmppTask<void> removeKeys(CSR encryption, CSR keyOwnerJid);
|
|
virtual QXmppTask<void> removeKeys(CSR encryption, CLBAR keyIds);
|
|
virtual QXmppTask<void> addKeys(CSR encryption, CSR keyOwnerJid, CLBAR keyIds, TL trustLevel);
|
|
virtual QXmppTask<QByteArray> ownKey(CSR encryption);
|
|
virtual QXmppTask<void> resetOwnKey(CSR encryption);
|
|
virtual QXmppTask<void> setOwnKey(CSR encryption, const QByteArray& keyId);
|
|
virtual QXmppTask<QXmpp::TrustSecurityPolicy> securityPolicy(CSR encryption);
|
|
virtual QXmppTask<void> resetSecurityPolicy(CSR encryption);
|
|
virtual QXmppTask<void> setSecurityPolicy(CSR encryption, QXmpp::TrustSecurityPolicy securityPolicy);
|
|
|
|
static TL convert(Shared::TrustLevel level);
|
|
static Shared::TrustLevel convert(TL level);
|
|
|
|
private:
|
|
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
|