57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
/*
|
|
* Created by victoria on 2021-05-13.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <QBuffer>
|
|
#include <QString>
|
|
#include <lmdb.h>
|
|
|
|
#include "key.h"
|
|
|
|
namespace QXmpp::Omemo {
|
|
|
|
class Bundle;
|
|
|
|
class Database {
|
|
public:
|
|
explicit Database(QString jid);
|
|
~Database();
|
|
Database(const Database &) = delete;
|
|
Database(Database &&) = delete;
|
|
Database &operator=(const Database &) = delete;
|
|
|
|
// For local user
|
|
std::optional<int> loadActiveDeviceId();
|
|
bool saveActiveDeviceId(int deviceId);
|
|
|
|
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);
|
|
|
|
const QString jid;
|
|
|
|
private:
|
|
MDB_env *env{};
|
|
MDB_dbi dbiDevices{};
|
|
MDB_dbi dbiKeys{};
|
|
MDB_dbi dbiPreKeys{};
|
|
MDB_dbi dbiIdentityKeys{};
|
|
};
|
|
|
|
} // namespace QXmpp::Omemo
|