aboutsummaryrefslogtreecommitdiff
path: root/lib/events
AgeCommit message (Collapse)Author
2022-08-25More code reorganisationAlexey Rusakov
- Common switchOnType() piece for key verification events is factored out into processIfVerificationEvent() - Bare event JSON removed from KeyVerificationSession into constructors of respective events - Connection::sendToDevice() uses assembleEncryptedContent() introduced in the previous commit - commonSupportedMethods() moved out to .cpp; error/string converters made static
2022-08-25Connection::Private::assembleEncryptedContent()Alexey Rusakov
What was partially factored out before into encryptSessionKeyEvent() is now the complete algorithm converting any event json into encrypted content.
2022-08-24Merge branch 'dev' into device-verificationAlexey Rusakov
# Conflicts: # autotests/testfilecrypto.cpp # lib/connection.cpp # lib/connection.h # lib/database.cpp # lib/database.h # lib/e2ee/qolmoutboundsession.cpp # lib/e2ee/qolmoutboundsession.h # lib/eventitem.h # lib/events/encryptedevent.cpp # lib/events/encryptedevent.h # lib/events/encryptedfile.cpp # lib/events/encryptedfile.h # lib/events/keyverificationevent.cpp # lib/events/keyverificationevent.h # lib/events/roomkeyevent.h # lib/room.cpp # lib/room.h
2022-08-05eventloader.h: use basicJson() in a uniform wayAlexey Rusakov
There's no particular reason the order of parameters in StateEventBase::basicJson() should be as it was, and (the only) loadStateEvent() usage in room.cpp suggests the unified order is more convenient. Besides, this order is aligned with that in the StateEventBase constructor.
2022-08-01Fix FTBFSAlexey Rusakov
2022-08-01Pull out common JsonConverter code to JsonObjectUnpackerAlexey Rusakov
2022-07-30moving eventCast(): disallow passing nullptrAlexey Rusakov
This is aligned with the non-moving version.
2022-07-29Moving eventCast()Alexey Rusakov
In a situation where you have an EventPtr that you want to place somewhere as an `event_ptr_tt<SomeMoreSpecificEventType>` you have to carefully check that the stored event is actually of SomeMoreSpecificType and if it is, release() that event pointer, downcast, and re-wrap it into that new event_ptr_tt - or, as can be seen from the diff here, re-loadEvent() from JSON, which is simpler but inefficient. To help clients, and the library, eventCast() can now accept an rvalue smart pointer and do all the necessary things with it.
2022-07-26...and the definitive fixAlexey Rusakov
2022-07-26Another fix attemptAlexey Rusakov
2022-07-26Hopefully fix building with GCCAlexey Rusakov
The last commit broke it.
2022-07-26Add missing QUOTIENT_API piecesAlexey Rusakov
The upcoming event type infrastructure finally helps to detect those omissions more or less reliably (for event types only though).
2022-07-13eventcontent.h: Use C++17 nested namespaces notationAlexey Rusakov
2022-07-12converters.*: facilities to convert enumsAlexey Rusakov
This introduces enumTo/FromJsonString() and flagTo/FromJsonString(), four facility functions to simplify conversion between C++ enums and JSON, and refactors a couple of places where it's useful.
2022-07-12Make AliasesEventContent a simple structureAlexey Rusakov
JSON conversions are moved out of the class, obviating the need to define the plain data constructor and gaining default-constructibility along the way - previously the default constructor was preempted by user-defined ones.
2022-07-12Refactor things around EncryptionEvent[Content]Alexey Rusakov
EncryptionEvent was marked as Q_GADGET only for the sake of defining EncryptionType inside of it as Q_ENUM, with aliases also available under Quotient:: and EncryptionEventContent. This is a legacy from pre-Q_ENUM_NS times. However, event types are not really made to be proper Q_GADGETs: Q_GADGET implies access by value or reference but event types are uncopyable for the former and QML is ill-equipped for the latter. This commit moves EncryptionType definition to where other such enumerations reside - on the namespace level in quotient_common.h; and the other two places are now deprecated; and EncryptionEvent is no more Q_GADGET. With fromJson/toJson refactored in the previous commit there's no more need to specialise JsonConverter<>: specialising fromJson() is just enough. Moving EncryptionType to quotient_common.h exposed the clash of two Undefined enumerators (in RoomType and EncryptionType), warranting both enumerations to become scoped (which they ought to be, anyway). And while we're at it, the base type of enumerations is specified explicitly, as MSVC apparently uses a signed base type (int?) by default, unlike other compilers, and the upcoming enum converters will assume an unsigned base type. Finally, using fillFromJson() instead of fromJson() in the EncryptionEventContent constructor allowed to make default values explicit in the header file, rather than buried in the initialisation code.
2022-07-12fromJson()/toJson() refactoringAlexey Rusakov
fromJson() is generalised to accept any JSON-like type while passing QJsonObject to JsonConverter<>::load (instead of doLoad). This allows to (still) rely on JsonConverter<> as a customisation point while providing an opportunity to overload fromJson for custom types in a pointed way (specifically, by providing the overload for `fromJson(const QJsonObject&)`), instead of having to go with full-blown JsonConverter<> specialisation. This will be used in a further commit to simplify ReceiptEvent definition. Using if constexpr in combination with constraints (`requires()`) - the first such case in Quotient codebase - allowed to put the entire logic in a single JsonConverter<>::load() body instead of having a facility JsonExporter<> class for SFINAE. Aside from that, fromJson<QJsonValue, QJsonValue> is entirely dropped because it's not supposed to be used that way (it's no-op after all); reflecting that, Event::unsignedPart() and Event::contentPart() no more default to QJsonValue as the expected return type, you have to explicitly provide the type instead (and as one can see from the changes in the commit, it's actually better that way since it's better to validate the value inside JSON - e.g. check QString or QJsonObject for emptiness - than the QJsonValue envelope which may still wrap an empty value). toJson() is also generalised, replacing 3 functions with one that has a constexpr if to discern between two kinds of types.
2022-07-12Fix deprecation messagesAlexey Rusakov
[skip ci]
2022-07-12Pack up StickerEvent in the header fileAlexey Rusakov
Dropping yet another translation unit.
2022-07-07Avoid std::derived_from and std::bind_frontAlexey Rusakov
Apple Clang doesn't have those yet.
2022-07-03Shorten switchOnType, function_traits and connect*Alexey Rusakov
...thanks to C++20 awesomeness. A notable change is that wrap_in_function() (and respectively function_traits<>::function_type) and fn_return_t alias are gone. The former are no more needed because connectUntil/connectSingleShot no more use std::function. The latter has been relatively underused and with the optimisation of switchOnType hereby, could be completely replaced with std::invoke_result_t. Rewriting connect* functions using constexpr and auto parameters made the implementation 30% more compact and much easier to understand (though still with a couple of - now thoroughly commented - tricky places). Dropping std::function<> from it may also bring some (quite modest, likely) performance benefits.
2022-06-24Make EventContent::Base() move constructor noexceptAlexey Rusakov
2022-06-23Streamline Room::P::shouldRotateMegolmSession()Alexey Rusakov
Now there's only 1 instead of 5 lookups of the same EncryptionEvent, and the code is shorter.
2022-06-23Use QUO_CONTENT_GETTERAlexey Rusakov
In keyverificationevent.*, this massively shortens repetitive getter definitions; the remaining few non-trivial ones are moved to keyverificationevent.h, dropping the respective .cpp file and therefore the dedicated translation unit. In roomkeyevent.h, it's just shorter.
2022-06-22Streamline RoomPowerLevelsEvent backoffice codeAlexey Rusakov
Also: leave a link at the place in the spec with power level defaults to make it clear they are not invented out of thin air.
2022-06-22Address a few more Sonar warningsAlexey Rusakov
2022-06-21Fix a few clang-tidy/GCC warningsAlexey Rusakov
2022-06-21Move out Overloads to util.hAlexey Rusakov
...instead of tucking the template in filesourceinfo.cpp where it surely will be forgotten.
2022-06-18Move C++-only macros to util.hAlexey Rusakov
This pertains to QUO_IMPLICIT and DECL_DEPRECATED_ENUMERATOR - both can be used with no connection to Qt meta-type system (which is what quotient_common.h is for).
2022-06-18Drop make_array(); use std::to_array() where neededAlexey Rusakov
make_array() has been introduced to cover for shortcomings on macOS and Windows. These shortcomings are no more there, so we can just use the standardrlibrary.
2022-05-29Move some Meg/Olm session logic from Room::Private to Connection::PrivateAlexey Rusakov
Functions (Room::Private::)createOlmSession, payloadForUserDevice and sendRoomKeyToDevices don't have a lot to do with the given Room object but deal with quite a few things stored in Connection. This commit moves them to Connection::Private, exposing sendSessionKeyToDevices (the new name for sendRoomKeyToDevices) in Connection so that Room could call it from Room::P::sendMegolmSession(). While moving these over, a few additional things were adjusted: - more functions marked as const - a few functions could be moved now from Connection to Connection::Private - false slots in Connection (such as picklingMode) are moved out of the slots block - keys.yml in Matrix CS API definitions has been adjusted to match the real structure of `/claim` response (see quotient-im/matrix-spec repo); csapi/keys.h has been regenerated accordingly.
2022-05-29Cleanup and address Sonar warningsAlexey Rusakov
2022-05-29Move encryptFile/decryptFile out of EncryptedFileMetadataAlexey Rusakov
These are not operations on EncryptedFileMetadata but rather on a combination of EncryptedFileMetadata and ciphertext. If C++ had multimethods these could be bound to such a combination.
2022-05-29Refactor EncryptedFile and EC::FileInfo::fileAlexey Rusakov
Besides having a misleading name (and it goes back to the spec), EncryptedFile under `file` key preempts the `url` (or `thumbnail_url`) string value so only one of the two should exist. This is a case for using std::variant<> - despite its clumsy syntax, it can actually simplify and streamline code when all the necessary bits are in place (such as conversion to JSON and getting the common piece - the URL - out of it). This commit replaces `FileInfo::url` and `FileInfo::file` with a common field `source` of type `FileSourceInfo` that is an alias for a variant type covering both underlying types; and `url()` is reintroduced as a function instead, to allow simplified access to whichever URL is available inside the variant. Oh, and EncryptedFile is EncryptedFileMetadata now, to clarify that it does not represent the file payload itself but rather the data necessary to obtain that payload.
2022-05-20Apply suggestions from code reviewTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2022-05-20Truncate ciphertext buffer to actual size during file encryptionTobias Fella
The ciphertext for AES CTR is exactly as large as the plaintext (not necessarily a multiple of the blocksize!). By truncating the ciphertext, we do not send bytes that will be decrypted to gibberish. As a side node, we probably do not need to initialize the ciphertext buffer larger than the plaintext size at all, but the OpenSSL docs are a bit vague about that.
2022-05-19Fix cipher text buffer initializationTobias Fella
2022-05-18Update lib/events/encryptedevent.cppTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2022-05-18Apply suggestions from code reviewTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2022-05-16Update lib/events/encryptedfile.hTobias Fella
2022-05-16More work; Update olm pickle & timestamps in database; Remove TODOsTobias Fella
2022-05-16Properly create encrypted editsTobias Fella
2022-05-16Implement sending encrypted filesTobias Fella
2022-05-16Add constructor for creating roomkeyeventsTobias Fella
2022-05-14Cleanup across the boardAlexey Rusakov
Mainly driven by clang-tidy and SonarCloud warnings (sadly, SonarCloud doesn't store historical reports so no link can be provided here).
2022-05-11CallAnswerEvent: drop lifetimeAlexey Rusakov
See https://github.com/matrix-org/matrix-spec/pull/1054. # Conflicts: # lib/events/callanswerevent.cpp # lib/events/callanswerevent.h
2022-05-08Merge #548: Streamline usage of event types, part 1Alexey Rusakov
2022-05-08QUO_CONTENT_GETTERAlexey Rusakov
To streamline adding of simple getters of content parts.
2022-05-08Use std::pair instead of QPairAlexey Rusakov
QPair is giving way to its STL counterpart, becoming its alias in Qt 6.
2022-05-08More cleanupAlexey Rusakov