Changeset View
Changeset View
Standalone View
Standalone View
src/client/device-list-tracker.hpp
| Show All 32 Lines | namespace Kazv | ||||
| struct DeviceKeyInfo | struct DeviceKeyInfo | ||||
| { | { | ||||
| std::string deviceId; | std::string deviceId; | ||||
| std::string ed25519Key; | std::string ed25519Key; | ||||
| std::string curve25519Key; | std::string curve25519Key; | ||||
| std::optional<std::string> displayName; | std::optional<std::string> displayName; | ||||
| DeviceTrustLevel trustLevel{Unseen}; | DeviceTrustLevel trustLevel{Unseen}; | ||||
| /// Whether this device has been deleted by its owner. | |||||
| /// Deleted devices are kept in the tracker for verifying | |||||
| /// past decrypted events, but are excluded from | |||||
| /// devicesToSendKeys(). | |||||
| bool deleted{false}; | |||||
| friend bool operator==(const DeviceKeyInfo &a, const DeviceKeyInfo &b) = default; | friend bool operator==(const DeviceKeyInfo &a, const DeviceKeyInfo &b) = default; | ||||
| friend bool operator!=(const DeviceKeyInfo &a, const DeviceKeyInfo &b) = default; | friend bool operator!=(const DeviceKeyInfo &a, const DeviceKeyInfo &b) = default; | ||||
| }; | }; | ||||
| template<class Archive> | template<class Archive> | ||||
| void serialize(Archive &ar, DeviceKeyInfo &i, std::uint32_t const /*version*/) | void serialize(Archive &ar, DeviceKeyInfo &i, std::uint32_t const version) | ||||
| { | { | ||||
| ar | ar | ||||
| & i.deviceId | & i.deviceId | ||||
| & i.ed25519Key | & i.ed25519Key | ||||
| & i.curve25519Key | & i.curve25519Key | ||||
| & i.displayName | & i.displayName | ||||
| & i.trustLevel | & i.trustLevel | ||||
| ; | ; | ||||
| if (version >= 1) { | |||||
| ar & i.deleted; | |||||
| } else { | |||||
| i.deleted = false; | |||||
| } | } | ||||
| } | |||||
| struct DeviceListTracker | struct DeviceListTracker | ||||
| { | { | ||||
| using DeviceMapT = immer::map<std::string /* deviceId */, DeviceKeyInfo>; | using DeviceMapT = immer::map<std::string /* deviceId */, DeviceKeyInfo>; | ||||
| immer::map<std::string /* userId */, bool /* outdated */> usersToTrackDeviceLists; | immer::map<std::string /* userId */, bool /* outdated */> usersToTrackDeviceLists; | ||||
| immer::map<std::string /* userId */, DeviceMapT> deviceLists; | immer::map<std::string /* userId */, DeviceMapT> deviceLists; | ||||
| template<class RangeT> | template<class RangeT> | ||||
| Show All 14 Lines | struct DeviceListTracker | ||||
| immer::flex_vector<std::string> outdatedUsers() const; | immer::flex_vector<std::string> outdatedUsers() const; | ||||
| std::optional<DeviceKeyInfo> verifyDeviceInfo(std::string userId, std::string deviceId, Api::QueryKeysJob::DeviceInformation deviceInfo) const; | std::optional<DeviceKeyInfo> verifyDeviceInfo(std::string userId, std::string deviceId, Api::QueryKeysJob::DeviceInformation deviceInfo) const; | ||||
| bool addDevice(std::string userId, std::string deviceId, Api::QueryKeysJob::DeviceInformation deviceInfo); | bool addDevice(std::string userId, std::string deviceId, Api::QueryKeysJob::DeviceInformation deviceInfo); | ||||
| void addVerifiedDeviceKeyInfo(std::string userId, std::string deviceId, DeviceKeyInfo info); | void addVerifiedDeviceKeyInfo(std::string userId, std::string deviceId, DeviceKeyInfo info); | ||||
| /// Mark a device as deleted by its owner. The device is kept | |||||
| /// in the tracker (for verifying past decrypted events) but | |||||
| /// will be excluded from devicesToSendKeys(). | |||||
| void markDeviceAsDeleted(std::string userId, std::string deviceId); | |||||
| void markUpToDate(std::string userId); | void markUpToDate(std::string userId); | ||||
| DeviceMapT devicesFor(std::string userId) const; | DeviceMapT devicesFor(std::string userId) const; | ||||
| std::optional<DeviceKeyInfo> get(std::string userId, std::string deviceId) const; | std::optional<DeviceKeyInfo> get(std::string userId, std::string deviceId) const; | ||||
| std::optional<DeviceKeyInfo> findByEd25519Key(std::string userId, std::string ed25519Key) const; | std::optional<DeviceKeyInfo> findByEd25519Key(std::string userId, std::string ed25519Key) const; | ||||
| std::optional<DeviceKeyInfo> findByCurve25519Key(std::string userId, std::string curve25519Key) const; | std::optional<DeviceKeyInfo> findByCurve25519Key(std::string userId, std::string curve25519Key) const; | ||||
| Show All 19 Lines | namespace Kazv | ||||
| { | { | ||||
| ar | ar | ||||
| & t.usersToTrackDeviceLists | & t.usersToTrackDeviceLists | ||||
| & t.deviceLists | & t.deviceLists | ||||
| ; | ; | ||||
| } | } | ||||
| } | } | ||||
| BOOST_CLASS_VERSION(Kazv::DeviceKeyInfo, 0) | BOOST_CLASS_VERSION(Kazv::DeviceKeyInfo, 1) | ||||
| BOOST_CLASS_VERSION(Kazv::DeviceListTracker, 0) | BOOST_CLASS_VERSION(Kazv::DeviceListTracker, 0) | ||||