libQuotient
A Qt library for building matrix clients
qolminboundsession.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 OlmInboundGroupSession;
10 
11 namespace Quotient {
12 
13 //! An in-bound group session is responsible for decrypting incoming
14 //! communication in a Megolm session.
15 class QUOTIENT_API QOlmInboundGroupSession
16 {
17 public:
18  //! Creates a new instance of `OlmInboundGroupSession`.
19  static QOlmExpected<QOlmInboundGroupSession> create(const QByteArray& key);
20  //! Import an inbound group session, from a previous export.
21  static QOlmExpected<QOlmInboundGroupSession> importSession(
22  const QByteArray& key);
23  //! Serialises an `OlmInboundGroupSession` to encrypted Base64.
24  QByteArray pickle(const PicklingKey& key) const;
25  //! Deserialises from encrypted Base64 that was previously obtained by pickling
26  //! an `OlmInboundGroupSession`.
27  static QOlmExpected<QOlmInboundGroupSession> unpickle(
28  QByteArray&& pickled, const PicklingKey& key);
29  //! Decrypts ciphertext received for this group session.
30  QOlmExpected<std::pair<QByteArray, uint32_t> > decrypt(const QByteArray& message);
31  //! Export the base64-encoded ratchet key for this session, at the given index,
32  //! in a format which can be used by import.
33  QOlmExpected<QByteArray> exportSession(uint32_t messageIndex);
34  //! Get the first message index we know how to decrypt.
35  uint32_t firstKnownIndex() const;
36  //! Get a base64-encoded identifier for this session.
37  QByteArray sessionId() const;
38  bool isVerified() const;
39 
40  //! The olm session that this session was received from.
41  //! Required to get the device this session is from.
42  QByteArray olmSessionId() const;
43  void setOlmSessionId(const QByteArray& newOlmSessionId);
44 
45  //! The sender of this session.
46  QString senderId() const;
47  void setSenderId(const QString& senderId);
48 
49  OlmErrorCode lastErrorCode() const;
50  const char* lastError() const;
51 
52 private:
53  QOlmInboundGroupSession();
54  CStructPtr<OlmInboundGroupSession> m_groupSession;
55  QByteArray m_olmSessionId;
56  QString m_senderId;
57  OlmInboundGroupSession* olmData = m_groupSession.get();
58 };
59 
60 using QOlmInboundGroupSessionPtr = std::unique_ptr<QOlmInboundGroupSession>;
61 } // namespace Quotient