diff options
-rw-r--r-- | lib/events/encryptionevent.h | 2 | ||||
-rw-r--r-- | lib/room.cpp | 30 |
2 files changed, 12 insertions, 20 deletions
diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h index c73e5598..945b17e7 100644 --- a/lib/events/encryptionevent.h +++ b/lib/events/encryptionevent.h @@ -52,6 +52,8 @@ public: QString algorithm() const { return content().algorithm; } int rotationPeriodMs() const { return content().rotationPeriodMs; } int rotationPeriodMsgs() const { return content().rotationPeriodMsgs; } + + bool useEncryption() const { return !algorithm().isEmpty(); } }; REGISTER_EVENT_TYPE(EncryptionEvent) } // namespace Quotient diff --git a/lib/room.cpp b/lib/room.cpp index 2d4cfeb4..35a89cc6 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -411,10 +411,17 @@ public: bool shouldRotateMegolmSession() const { - if (!q->usesEncryption()) { + const auto* encryptionConfig = currentState.get<EncryptionEvent>(); + if (!encryptionConfig || !encryptionConfig->useEncryption()) return false; - } - return currentOutboundMegolmSession->messageCount() >= rotationMessageCount() || currentOutboundMegolmSession->creationTime().addMSecs(rotationInterval()) < QDateTime::currentDateTime(); + + const auto rotationInterval = encryptionConfig->rotationPeriodMs(); + const auto rotationMessageCount = encryptionConfig->rotationPeriodMsgs(); + return currentOutboundMegolmSession->messageCount() + >= rotationMessageCount + || currentOutboundMegolmSession->creationTime().addMSecs( + rotationInterval) + < QDateTime::currentDateTime(); } bool hasValidMegolmSession() const @@ -425,23 +432,6 @@ public: return currentOutboundMegolmSession != nullptr; } - /// Time in milliseconds after which the outgoing megolmsession should be replaced - unsigned int rotationInterval() const - { - if (!q->usesEncryption()) { - return 0; - } - return q->getCurrentState<EncryptionEvent>()->rotationPeriodMs(); - } - - // Number of messages sent by this user after which the outgoing megolm session should be replaced - int rotationMessageCount() const - { - if (!q->usesEncryption()) { - return 0; - } - return q->getCurrentState<EncryptionEvent>()->rotationPeriodMsgs(); - } void createMegolmSession() { qCDebug(E2EE) << "Creating new outbound megolm session for room " << q->objectName(); |