12 #include <nlohmann/json.hpp>
14 #include <immer/map.hpp>
15 #include <immer/flex_vector.hpp>
174 bool verify(
nlohmann::json object, std::string userId, std::string deviceId, std::string ed25519Key);
225 immer::map<std::string, immer::map<std::string ,
226 std::string >> keyMap)
const;
243 std::string theirIdentityKey,
244 std::string theirOneTimeKey);
246 template<
class Archive>
247 void save(Archive & ar,
const unsigned int )
const {
251 template<
class Archive>
252 void load(Archive &ar,
const unsigned int ) {
255 loadJson(nlohmann::json::parse(std::move(j)));
258 BOOST_SERIALIZATION_SPLIT_MEMBER()
Definition: crypto.hpp:36
void load(Archive &ar, const unsigned int)
Definition: crypto.hpp:252
nlohmann::json encryptMegOlm(nlohmann::json eventJson)
returns the content template with everything but deviceId eventJson should contain type,...
Definition: crypto.cpp:491
bool createInboundGroupSession(KeyOfGroupSession k, std::string sessionKey, std::string ed25519Key)
Create or update an inbound group session.
Definition: crypto.cpp:366
static std::size_t encryptOlmMaxRandomSize()
Definition: crypto.cpp:466
std::string curve25519IdentityKey() const
Definition: crypto.cpp:275
static std::size_t rotateMegOlmSessionRandomSize()
Definition: crypto.cpp:519
bool verify(nlohmann::json object, std::string userId, std::string deviceId, std::string ed25519Key)
Check whether the signature of userId/deviceId is valid in object.
Definition: crypto.cpp:400
Crypto & operator=(const Crypto &that)
Definition: crypto.cpp:236
std::string outboundGroupSessionInitialKey(std::string roomId)
Definition: crypto.cpp:540
nlohmann::json toJson() const
Definition: crypto.cpp:601
static std::size_t createOutboundSessionRandomSize()
Definition: crypto.cpp:577
static std::size_t genOneTimeKeysRandomSize(int num)
Get the size of random data needed to generate num one-time keys.
Definition: crypto.cpp:308
int uploadedOneTimeKeysCount(std::string algorithm) const
Definition: crypto.cpp:349
bool hasInboundGroupSession(KeyOfGroupSession k) const
Definition: crypto.cpp:371
void genOneTimeKeysWithRandom(RandomData random, int num)
Generate num one-time keys with user-provided random data.
Definition: crypto.cpp:313
std::string ed25519IdentityKey() const
Definition: crypto.cpp:270
MaybeString getInboundGroupSessionEd25519KeyFromEvent(const nlohmann::json &eventJson) const
Definition: crypto.cpp:427
void setUploadedOneTimeKeysCount(immer::map< std::string, int > uploadedOneTimeKeysCount)
Definition: crypto.cpp:298
void createOutboundSessionWithRandom(RandomData random, std::string theirIdentityKey, std::string theirOneTimeKey)
Create an outbound session using user-provided random data.
Definition: crypto.cpp:582
void markOneTimeKeysAsPublished()
Definition: crypto.cpp:338
void loadJson(const nlohmann::json &j)
Definition: crypto.cpp:618
nlohmann::json unpublishedOneTimeKeys() const
According to olm.h, this returns an object like.
Definition: crypto.cpp:322
std::size_t maxNumberOfOneTimeKeys() const
Definition: crypto.cpp:303
immer::map< std::string, immer::flex_vector< std::string > > UserIdToDeviceIdMap
Definition: crypto.hpp:223
UserIdToDeviceIdMap devicesMissingOutboundSessionKey(immer::map< std::string, immer::map< std::string, std::string >> keyMap) const
Definition: crypto.cpp:552
bool valid() const
Definition: crypto.cpp:253
std::string sign(nlohmann::json j)
Definition: crypto.cpp:280
std::string outboundGroupSessionCurrentKey(std::string roomId)
Definition: crypto.cpp:546
std::string rotateMegOlmSessionWithRandom(RandomData random, Timestamp timeMs, std::string roomId)
Rotate the megolm session using user-provided random data.
Definition: crypto.cpp:524
MaybeString decrypt(nlohmann::json eventJson)
Returns decrypted message if we can decrypt it otherwise returns the error.
Definition: crypto.cpp:354
int numUnpublishedOneTimeKeys() const
Definition: crypto.cpp:344
nlohmann::json encryptOlmWithRandom(RandomData random, nlohmann::json eventJson, std::string theirCurve25519IdentityKey)
Encrypt eventJson with olm, for the recipient identified with theirCurve25519IdentityKey.
Definition: crypto.cpp:471
std::optional< std::string > rotateMegOlmSessionWithRandomIfNeeded(RandomData random, Timestamp timeMs, std::string roomId, MegOlmSessionRotateDesc desc)
Rotate the megolm session using user-provided random data, if we need to rotate it.
Definition: crypto.cpp:532
Crypto()
Construct an invalid Crypto.
Definition: crypto.cpp:214
void save(Archive &ar, const unsigned int) const
Definition: crypto.hpp:247
std::size_t encryptOlmRandomSize(std::string theirCurve25519IdentityKey) const
Definition: crypto.cpp:444
bool operator==(const Crypto &that) const
Definition: crypto.cpp:248
static std::size_t constructRandomSize()
Definition: crypto.cpp:209
Definition: session.hpp:27
Definition: location.hpp:10
std::string RandomData
Definition: crypto-util.hpp:34
nlohmann::json json
Definition: jsonwrap.hpp:20
std::int_fast64_t Timestamp
Definition: event.hpp:18
Definition: location.hpp:27
Definition: clientutil.hpp:217
Definition: crypto-p.hpp:26
Definition: crypto-util.hpp:24
Definition: crypto.hpp:27
int messages
The message limit of the megolm session.
Definition: crypto.hpp:31
Timestamp ms
The time limit of the megolm session, in milliseconds.
Definition: crypto.hpp:29
The tag to indicate that a constructor should use user-provided random data.
Definition: crypto-util.hpp:32
Definition: session-p.hpp:16