Exemple #1
0
 async def get_encryption_info(self, room_id: RoomID
                               ) -> Optional[RoomEncryptionStateEventContent]:
     row = await self.db.fetchrow("SELECT is_encrypted, encryption FROM mx_room_state "
                                  "WHERE room_id=$1", room_id)
     if row is None or not row["is_encrypted"]:
         return None
     return RoomEncryptionStateEventContent.parse_json(row["encryption"])
 async def get_encryption_info(self, room_id: RoomID) -> RoomEncryptionStateEventContent | None:
     val = await self.db.fetchval(
         "SELECT encryption FROM mx_room_state WHERE room_id=$1", room_id
     )
     if not val:
         return None
     return RoomEncryptionStateEventContent.parse_json(val)
Exemple #3
0
 async def set_encryption_info(
         self, room_id: RoomID,
         content: RoomEncryptionStateEventContent) -> None:
     q = (
         "INSERT INTO mx_room_state (room_id, is_encrypted, encryption) VALUES ($1, true, $2) "
         "ON CONFLICT (room_id) DO UPDATE SET is_encrypted=true, encryption=$2"
     )
     await self.db.execute(q, room_id, content.json())
Exemple #4
0
 def deserialize(self, data: Dict[str, Any]) -> None:
     self.members = {
         room_id: {
             user_id: Member.deserialize(member)
             for user_id, member in members.items()
         }
         for room_id, members in data["members"].items()
     }
     self.full_member_list = data["full_member_list"]
     self.power_levels = {
         room_id: PowerLevelStateEventContent.deserialize(content)
         for room_id, content in data["power_levels"].items()
     }
     self.encryption = {
         room_id: (RoomEncryptionStateEventContent.deserialize(content)
                   if content is not None else None)
         for room_id, content in data["encryption"].items()
     }
Exemple #5
0
    def deserialize(self, data: SerializedStateStore) -> None:
        """
        Parse a previously serialized dict into this state store.

        Args:
            data: A dict returned by :meth:`serialize`.
        """
        self.members = {
            room_id: {
                user_id: Member.deserialize(member)
                for user_id, member in members.items()
            }
            for room_id, members in data["members"].items()
        }
        self.full_member_list = data["full_member_list"]
        self.power_levels = {
            room_id: PowerLevelStateEventContent.deserialize(content)
            for room_id, content in data["power_levels"].items()
        }
        self.encryption = {
            room_id: (RoomEncryptionStateEventContent.deserialize(content)
                      if content is not None else None)
            for room_id, content in data["encryption"].items()
        }
Exemple #6
0
 def get_encryption_state_event_json(self) -> JSON:
     evt = RoomEncryptionStateEventContent(EncryptionAlgorithm.MEGOLM_V1)
     if self.bridge.config["bridge.encryption.rotation.enable_custom"]:
         evt.rotation_period_ms = self.bridge.config["bridge.encryption.rotation.milliseconds"]
         evt.rotation_period_msgs = self.bridge.config["bridge.encryption.rotation.messages"]
     return evt.serialize()