Changeset View
Changeset View
Standalone View
Standalone View
src/crypto/crypto.cpp
| Show All 12 Lines | |||||
| #include <vodozemac.h> | #include <vodozemac.h> | ||||
| #include <nlohmann/json.hpp> | #include <nlohmann/json.hpp> | ||||
| #include <debug.hpp> | #include <debug.hpp> | ||||
| #include <event.hpp> | #include <event.hpp> | ||||
| #include <cursorutil.hpp> | #include <cursorutil.hpp> | ||||
| #include <types.hpp> | #include <types.hpp> | ||||
| #include <validator.hpp> | |||||
| #include "crypto-p.hpp" | #include "crypto-p.hpp" | ||||
| #include "session-p.hpp" | #include "session-p.hpp" | ||||
| #include "crypto-util-p.hpp" | #include "crypto-util-p.hpp" | ||||
| #include "crypto-util.hpp" | #include "crypto-util.hpp" | ||||
| #include "time-util.hpp" | #include "time-util.hpp" | ||||
| namespace Kazv | namespace Kazv | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 331 Lines • ▼ Show 20 Lines | MaybeString Crypto::decrypt(nlohmann::json eventJson) | ||||
| return m_d->decryptMegOlm(eventJson); | return m_d->decryptMegOlm(eventJson); | ||||
| } | } | ||||
| return NotBut("Algorithm " + algo + " not supported"); | return NotBut("Algorithm " + algo + " not supported"); | ||||
| } | } | ||||
| bool Crypto::createInboundGroupSession(KeyOfGroupSession k, std::string sessionKey, std::string ed25519Key) | bool Crypto::createInboundGroupSession(KeyOfGroupSession k, std::string sessionKey, std::string ed25519Key) | ||||
| { | { | ||||
| return m_d->createInboundGroupSession(std::move(k), std::move(sessionKey), std::move(ed25519Key)); | return m_d->createInboundGroupSession(std::move(k), std::move(sessionKey), std::move(ed25519Key)); | ||||
| } | |||||
| std::size_t Crypto::importInboundGroupSessions(const nlohmann::json &keys) | |||||
| { | |||||
| if (!keys.is_array()) { | |||||
| return 0; | |||||
| } | |||||
| auto validateStr = identValidate(&nlohmann::json::is_string); | |||||
| std::size_t count = 0; | |||||
| for (const auto &data : keys) { | |||||
| if (!data.is_object()) { | |||||
| continue; | |||||
| } | |||||
| auto key = nlohmann::json::object(); | |||||
| if (!(cast(key, data, "algorithm", identValidate([](const auto &j) { | |||||
| return j == "m.megolm.v1.aes-sha2"; | |||||
| })) && cast(key, data, "room_id", validateStr) | |||||
| && cast(key, data, "sender_key", validateStr) | |||||
| && cast(key, data, "session_id", validateStr) | |||||
| && cast(key, data, "session_key", validateStr) | |||||
| )) { | |||||
| continue; | |||||
| } | |||||
| auto keyOfGroupSession = KeyOfGroupSession{ | |||||
| key["room_id"].template get<std::string>(), | |||||
| key["session_id"].template get<std::string>(), | |||||
| }; | |||||
| if (createInboundGroupSession( | |||||
| keyOfGroupSession, | |||||
| key["session_key"].template get<std::string>(), | |||||
| key["sender_key"].template get<std::string>() | |||||
| )) { | |||||
| ++count; | |||||
| } | |||||
| } | |||||
| return count; | |||||
| } | } | ||||
| bool Crypto::hasInboundGroupSession(KeyOfGroupSession k) const | bool Crypto::hasInboundGroupSession(KeyOfGroupSession k) const | ||||
| { | { | ||||
| return m_d->inboundGroupSessions.find(k) != m_d->inboundGroupSessions.end(); | return m_d->inboundGroupSessions.find(k) != m_d->inboundGroupSessions.end(); | ||||
| } | } | ||||
| bool CryptoPrivate::createInboundGroupSession(KeyOfGroupSession k, std::string sessionKey, std::string ed25519Key) | bool CryptoPrivate::createInboundGroupSession(KeyOfGroupSession k, std::string sessionKey, std::string ed25519Key) | ||||
| ▲ Show 20 Lines • Show All 260 Lines • Show Last 20 Lines | |||||