diff --git a/include/mtxclient/crypto/client.hpp b/include/mtxclient/crypto/client.hpp index 0d62329ab80596164f5e7acbfd45280f79f19401..5ca5ec1b3354dc95857847005b8c2464f4f9d2f8 100644 --- a/include/mtxclient/crypto/client.hpp +++ b/include/mtxclient/crypto/client.hpp @@ -347,9 +347,11 @@ session_id(OlmOutboundGroupSession *s); std::string session_key(OlmOutboundGroupSession *s); -//! Retrieve the session key from an *inbound* megolm session. +// @brief Retrieve the session key from an *inbound* megolm session with a specific minimum index. +// +// Use -1 to use the smallest index possible std::string -export_session(OlmInboundGroupSession *s); +export_session(OlmInboundGroupSession *s, uint32_t at_index); //! Create an *inbound* megolm session from an exported session key. InboundGroupSessionPtr diff --git a/lib/crypto/client.cpp b/lib/crypto/client.cpp index 73e3ea78d7b022b5b387ff066a048d1ad342a849..95cfb35e4a5e49673bb1df3957d5842265950635 100644 --- a/lib/crypto/client.cpp +++ b/lib/crypto/client.cpp @@ -659,10 +659,11 @@ mtx::crypto::session_key(OlmOutboundGroupSession *s) } std::string -mtx::crypto::export_session(OlmInboundGroupSession *s) +mtx::crypto::export_session(OlmInboundGroupSession *s, uint32_t at_index) { - const size_t len = olm_export_inbound_group_session_length(s); - const uint32_t index = olm_inbound_group_session_first_known_index(s); + const size_t len = olm_export_inbound_group_session_length(s); + const uint32_t index = + at_index == uint32_t(-1) ? olm_inbound_group_session_first_known_index(s) : at_index; auto session_key = create_buffer(len); const std::size_t ret = diff --git a/tests/e2ee.cpp b/tests/e2ee.cpp index 20b0e339999ae2c3cfc8943a513f207b5ef1e3dc..fd8a424c74273632daa10c4a4739bbb5512f6e10 100644 --- a/tests/e2ee.cpp +++ b/tests/e2ee.cpp @@ -1270,7 +1270,7 @@ TEST(ExportSessions, InboundMegolmSessions) // ==================== SESSION IMPORT/EXPORT =================== // - auto exported_session_key = export_session(inbound_megolm_session.get()); + auto exported_session_key = export_session(inbound_megolm_session.get(), -1); auto restored_inbound_session = import_session(exported_session_key); // Decrypt message again.