aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2021-09-11 16:18:35 +0200
committerTobias Fella <fella@posteo.de>2021-09-11 21:02:47 +0200
commit0209be8305aa38722a3d25593ae71fbb3ac05e52 (patch)
treeab80c8b140f483c408209922a0c72b06912bd3a1
parent9e548e0625a819052cd10d5c4bf129dde649a6a4 (diff)
downloadlibquotient-0209be8305aa38722a3d25593ae71fbb3ac05e52.tar.gz
libquotient-0209be8305aa38722a3d25593ae71fbb3ac05e52.zip
Add convenience function for activating encryption and fix
EncryptionEvent constructor
-rw-r--r--lib/events/encryptionevent.cpp8
-rw-r--r--lib/events/encryptionevent.h4
-rw-r--r--lib/room.cpp9
-rw-r--r--lib/room.h6
4 files changed, 24 insertions, 3 deletions
diff --git a/lib/events/encryptionevent.cpp b/lib/events/encryptionevent.cpp
index 490a5e8a..aa05a96e 100644
--- a/lib/events/encryptionevent.cpp
+++ b/lib/events/encryptionevent.cpp
@@ -39,6 +39,14 @@ EncryptionEventContent::EncryptionEventContent(const QJsonObject& json)
, rotationPeriodMsgs(json[RotationPeriodMsgsKeyL].toInt(100))
{}
+EncryptionEventContent::EncryptionEventContent(EncryptionType et)
+ : encryption(et)
+{
+ if(encryption != Undefined) {
+ algorithm = encryptionStrings[encryption];
+ }
+}
+
void EncryptionEventContent::fillJson(QJsonObject* o) const
{
Q_ASSERT(o);
diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h
index 65ee4187..14439fcc 100644
--- a/lib/events/encryptionevent.h
+++ b/lib/events/encryptionevent.h
@@ -12,9 +12,7 @@ class EncryptionEventContent : public EventContent::Base {
public:
enum EncryptionType : size_t { MegolmV1AesSha2 = 0, Undefined };
- explicit EncryptionEventContent(EncryptionType et = Undefined)
- : encryption(et)
- {}
+ explicit EncryptionEventContent(EncryptionType et = Undefined);
explicit EncryptionEventContent(const QJsonObject& json);
EncryptionType encryption;
diff --git a/lib/room.cpp b/lib/room.cpp
index c6cca2ea..ced313a4 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -3009,3 +3009,12 @@ bool MemberSorter::operator()(User* u1, QStringView u2name) const
return n1.localeAwareCompare(n2) < 0;
}
+
+void Room::activateEncryption()
+{
+ if(usesEncryption()) {
+ qCWarning(E2EE) << "Room" << objectName() << "is already encrypted";
+ return;
+ }
+ setState<EncryptionEvent>(EncryptionEventContent::MegolmV1AesSha2);
+}
diff --git a/lib/room.h b/lib/room.h
index 4e55dbaf..c18d0b36 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -604,6 +604,12 @@ public Q_SLOTS:
void answerCall(const QString& callId, const QString& sdp);
void hangupCall(const QString& callId);
+ /**
+ * Activates encryption for this room.
+ * Warning: Cannot be undone
+ */
+ void activateEncryption();
+
Q_SIGNALS:
/// Initial set of state events has been loaded
/**