libQuotient
A Qt library for building matrix clients
qolmoutboundsession.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 
5 #pragma once
6 
7 #include <Quotient/e2ee/e2ee_common.h>
8 
9 struct OlmOutboundGroupSession;
10 
11 namespace Quotient {
12 
13 //! An out-bound group session is responsible for encrypting outgoing
14 //! communication in a Megolm session.
15 class QUOTIENT_API QOlmOutboundGroupSession
16 {
17 public:
18  QOlmOutboundGroupSession();
19 
20  //! Serialises a `QOlmOutboundGroupSession` to encrypted Base64.
21  QByteArray pickle(const PicklingKey &key) const;
22  //! Deserialises from encrypted Base64 that was previously obtained by
23  //! pickling a `QOlmOutboundGroupSession`.
24  static QOlmExpected<QOlmOutboundGroupSession> unpickle(QByteArray&& pickled, const PicklingKey& key);
25 
26  //! Encrypts a plaintext message using the session.
27  QByteArray encrypt(const QByteArray& plaintext) const;
28 
29  //! Get the current message index for this session.
30  //!
31  //! Each message is sent with an increasing index; this returns the
32  //! index for the next message.
33  uint32_t sessionMessageIndex() const;
34 
35  //! Get a base64-encoded identifier for this session.
36  QByteArray sessionId() const;
37 
38  //! Get the base64-encoded current ratchet key for this session.
39  //!
40  //! Each message is sent with a different ratchet key. This function returns the
41  //! ratchet key that will be used for the next message.
42  QByteArray sessionKey() const;
43 
44  int messageCount() const;
45  void setMessageCount(int messageCount);
46 
47  QDateTime creationTime() const;
48  void setCreationTime(const QDateTime& creationTime);
49 
50  OlmErrorCode lastErrorCode() const;
51  const char* lastError() const;
52 
53 private:
54  CStructPtr<OlmOutboundGroupSession> m_groupSession;
55  int m_messageCount = 0;
56  QDateTime m_creationTime = QDateTime::currentDateTime();
57  OlmOutboundGroupSession* olmData = m_groupSession.get();
58 };
59 
60 } // namespace Quotient