#include "mtx/common.hpp" #include using json = nlohmann::json; namespace mtx { namespace crypto { void from_json(const json &obj, UnsignedDeviceInfo &res) { if (obj.find("device_display_name") != obj.end()) res.device_display_name = obj.at("device_display_name").get(); } void to_json(json &obj, const UnsignedDeviceInfo &res) { if (!res.device_display_name.empty()) obj["device_display_name"] = res.device_display_name; } void from_json(const json &obj, DeviceKeys &res) { res.user_id = obj.at("user_id").get(); res.device_id = obj.at("device_id").get(); res.algorithms = obj.at("algorithms").get>(); res.keys = obj.at("keys").get>(); if (obj.contains("signatures")) res.signatures = obj.at("signatures").get>>(); if (obj.find("unsigned") != obj.end()) res.unsigned_info = obj.at("unsigned").get(); } void to_json(json &obj, const DeviceKeys &res) { obj["user_id"] = res.user_id; obj["device_id"] = res.device_id; obj["algorithms"] = res.algorithms; obj["keys"] = res.keys; obj["signatures"] = res.signatures; if (!res.unsigned_info.device_display_name.empty()) obj["unsigned"] = res.unsigned_info; } void from_json(const json &obj, CrossSigningKeys &res) { res.user_id = obj.at("user_id").get(); res.usage = obj.at("usage").get>(); res.keys = obj.at("keys").get>(); if (obj.contains("signatures")) res.signatures = obj.at("signatures").get>>(); } void to_json(json &obj, const CrossSigningKeys &res) { obj["user_id"] = res.user_id; obj["usage"] = res.usage; obj["keys"] = res.keys; obj["signatures"] = res.signatures; } void from_json(const json &obj, JWK &res) { res.kty = obj.at("kty").get(); res.key_ops = obj.at("key_ops").get>(); res.alg = obj.at("alg").get(); res.k = obj.at("k").get(); res.ext = obj.at("ext").get(); } void to_json(json &obj, const JWK &res) { obj["kty"] = res.kty; obj["key_ops"] = res.key_ops; obj["alg"] = res.alg; obj["k"] = res.k; obj["ext"] = res.ext; } void from_json(const json &obj, EncryptedFile &res) { res.url = obj.at("url").get(); res.key = obj.at("key").get(); res.iv = obj.at("iv").get(); res.hashes = obj.at("hashes").get>(); res.v = obj.at("v").get(); } void to_json(json &obj, const EncryptedFile &res) { obj["url"] = res.url; obj["key"] = res.key; obj["iv"] = res.iv; obj["hashes"] = res.hashes; obj["v"] = res.v; } } }