File indexing completed on 2024-05-12 05:01:58

0001 /*
0002   SPDX-FileCopyrightText: 2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "e2ekeymanager.h"
0008 #include "connection.h"
0009 #include "e2e/fetchmykeysjob.h"
0010 #include "rocketchataccount.h"
0011 #include "ruqola_encryption_debug.h"
0012 
0013 E2eKeyManager::E2eKeyManager(RocketChatAccount *account, QObject *parent)
0014     : QObject{parent}
0015     , mAccount(account)
0016 {
0017 }
0018 
0019 E2eKeyManager::~E2eKeyManager() = default;
0020 
0021 void E2eKeyManager::decodeEncryptionKey()
0022 {
0023     // TODO
0024 }
0025 
0026 void E2eKeyManager::fetchMyKeys()
0027 {
0028     auto job = new RocketChatRestApi::FetchMyKeysJob(this);
0029     mAccount->restApi()->initializeRestApiJob(job);
0030     connect(job, &RocketChatRestApi::FetchMyKeysJob::fetchMyKeysDone, this, &E2eKeyManager::fetchMyKeysDone);
0031     if (!job->start()) {
0032         qCDebug(RUQOLA_ENCRYPTION_LOG) << "Impossible to start fetchmykeys job";
0033     }
0034 }
0035 
0036 bool E2eKeyManager::needToDecodeEncryptionKey() const
0037 {
0038     if (!mAccount) {
0039         return false;
0040     }
0041     if (mAccount->encryptionEnabled()) {
0042         // TODO check if we have decoded key stored.
0043         return true;
0044     }
0045     return false;
0046 }
0047 
0048 #include "moc_e2ekeymanager.cpp"