squawk/qomemo/database.h

57 lines
1.5 KiB
C
Raw Normal View History

2021-05-13 14:50:59 +00:00
/*
* Created by victoria on 2021-05-13.
*/
#pragma once
#include <QBuffer>
#include <QString>
#include <lmdb.h>
2021-07-22 17:45:39 +00:00
#include "key.h"
2021-05-13 14:50:59 +00:00
namespace QXmpp::Omemo {
2021-07-22 17:45:39 +00:00
class Bundle;
2021-05-13 14:54:37 +00:00
class Database {
public:
explicit Database(QString jid);
~Database();
Database(const Database &) = delete;
Database(Database &&) = delete;
Database &operator=(const Database &) = delete;
2021-07-22 17:45:39 +00:00
// For local user
std::optional<int> loadActiveDeviceId();
2021-05-13 14:54:37 +00:00
bool saveActiveDeviceId(int deviceId);
2021-07-22 17:45:39 +00:00
std::optional<QByteArray> loadIdentityKeySecret(int deviceId);
bool saveIdentityKeySecret(int deviceId, const QByteArray &identityKeySecret);
std::optional<Bundle> loadBundle(int deviceId);
bool saveBundle(int deviceId, const Bundle& bundle);
// For any user
std::optional<QByteArray> loadIdentityKey(int deviceId);
bool saveIdentityKey(int deviceId, const QByteArray &identityKey);
bool containsPreKey();
std::optional<KeyPair> loadPreKey(int deviceId, int id);
bool savePreKey(int deviceId, int id, const KeyPair &preKey);
std::optional<SignedPreKey> loadSignedPreKey(int deviceId);
bool saveSignedPreKey(int deviceId, const SignedPreKey& signedPreKey);
2021-05-13 14:54:37 +00:00
const QString jid;
private:
MDB_env *env{};
MDB_dbi dbiDevices{};
MDB_dbi dbiKeys{};
MDB_dbi dbiPreKeys{};
MDB_dbi dbiIdentityKeys{};
};
2021-05-13 14:50:59 +00:00
} // namespace QXmpp::Omemo