Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F112644
D68.1732340108.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D68.1732340108.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 9:35 PM (32 m, 17 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39118
Default Alt Text
D68.1732340108.diff (2 KB)
Attached To
Mode
D68: Create function Crypto::hasInboundGroupSession()
Attached
Detach File
Event Timeline
Log In to Comment