Page MenuHomePhorge

D68.1730839878.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D68.1730839878.diff

diff --git a/src/crypto/crypto.hpp b/src/crypto/crypto.hpp
--- a/src/crypto/crypto.hpp
+++ b/src/crypto/crypto.hpp
@@ -155,6 +155,8 @@
bool createInboundGroupSession(KeyOfGroupSession k, std::string sessionKey, std::string ed25519Key);
+ bool hasInboundGroupSession(KeyOfGroupSession k) const;
+
std::string outboundGroupSessionInitialKey(std::string roomId);
std::string outboundGroupSessionCurrentKey(std::string roomId);
diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp
--- a/src/crypto/crypto.cpp
+++ b/src/crypto/crypto.cpp
@@ -405,6 +405,11 @@
return m_d->createInboundGroupSession(std::move(k), std::move(sessionKey), std::move(ed25519Key));
}
+ bool Crypto::hasInboundGroupSession(KeyOfGroupSession k) const
+ {
+ return m_d->inboundGroupSessions.find(k) != m_d->inboundGroupSessions.end();
+ }
+
bool CryptoPrivate::createInboundGroupSession(KeyOfGroupSession k, std::string sessionKey, std::string ed25519Key)
{
auto session = InboundGroupSession(sessionKey, ed25519Key);
diff --git a/src/tests/crypto-test.cpp b/src/tests/crypto-test.cpp
--- a/src/tests/crypto-test.cpp
+++ b/src/tests/crypto-test.cpp
@@ -1,6 +1,6 @@
/*
* This file is part of libkazv.
- * SPDX-FileCopyrightText: 2020-2021 Tusooa Zhu <tusooa@kazv.moe>
+ * SPDX-FileCopyrightText: 2020-2024 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
@@ -474,3 +474,36 @@
REQUIRE(res1 == res3);
REQUIRE(res1 == reference);
}
+
+TEST_CASE("Crypto::hasInboundGroupSession", "[crypto][group-session]")
+{
+ Crypto crypto(RandomTag{}, genRandomData(Crypto::constructRandomSize()));
+
+ // creating a outbound group session will add it to inbound group sessions
+ crypto.rotateMegOlmSessionWithRandom(
+ genRandomData(Crypto::rotateMegOlmSessionRandomSize()),
+ 0,
+ "!someroom:example.com"
+ );
+
+ // encrypt to get the session id
+ auto ev = crypto.encryptMegOlm(R"({
+ "content": {},
+ "type": "m.room.message",
+ "room_id": "!someroom:example.com"
+ })"_json);
+
+ auto sessionId = ev["session_id"].template get<std::string>();
+
+ REQUIRE(crypto.hasInboundGroupSession(KeyOfGroupSession{
+ "!someroom:example.com",
+ crypto.curve25519IdentityKey(),
+ sessionId,
+ }));
+
+ REQUIRE(!crypto.hasInboundGroupSession(KeyOfGroupSession{
+ "!someroom:example.com",
+ crypto.curve25519IdentityKey(),
+ sessionId + "something something",
+ }));
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 5, 12:51 PM (16 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34733
Default Alt Text
D68.1730839878.diff (2 KB)

Event Timeline