# HG changeset patch # User Goffi # Date 1667084792 -7200 # Node ID 4836b81c5f31588863deede0fb621cdf63de5d5b # Parent da0e772881c309e7983ecfdffaa38217281adfa2 plugin XEP-0373: minor renaming + set `gpg_provider` in client: - `sat` and `self.__sat` have been renamed to `host` and `self.host` for consistency with other plugins. - `gpg_provider` is set in client while profile is connecting, so the instance is easily accessible to plugins depending on XEP-0373 rel 381 diff -r da0e772881c3 -r 4836b81c5f31 sat/plugins/plugin_xep_0373.py --- a/sat/plugins/plugin_xep_0373.py Fri Oct 28 18:47:17 2022 +0200 +++ b/sat/plugins/plugin_xep_0373.py Sun Oct 30 01:06:32 2022 +0200 @@ -1004,23 +1004,23 @@ Implementation of XEP-0373: OpenPGP for XMPP under namespace ``urn:xmpp:openpgp:0``. """ - def __init__(self, sat: SAT) -> None: + def __init__(self, host: SAT) -> None: """ @param sat: The SAT instance. """ - self.__sat = sat + self.host = host # Add configuration option to choose between manual trust and BTBV as the trust # model - sat.memory.updateParams(DEFAULT_TRUST_MODEL_PARAM) + host.memory.updateParams(DEFAULT_TRUST_MODEL_PARAM) - self.__xep_0045 = cast(Optional[XEP_0045], sat.plugins.get("XEP-0045")) - self.__xep_0060 = cast(XEP_0060, sat.plugins["XEP-0060"]) + self.__xep_0045 = cast(Optional[XEP_0045], host.plugins.get("XEP-0045")) + self.__xep_0060 = cast(XEP_0060, host.plugins["XEP-0060"]) self.__storage: Dict[str, persistent.LazyPersistentBinaryDict] = {} - xep_0163 = cast(XEP_0163, sat.plugins["XEP-0163"]) + xep_0163 = cast(XEP_0163, host.plugins["XEP-0163"]) xep_0163.addPEPEvent( "OX_PUBLIC_KEYS_LIST", PUBLIC_KEYS_LIST_NODE, @@ -1029,6 +1029,9 @@ ) ) + async def profileConnecting(self, client): + client.gpg_provider = get_gpg_provider(self.host, client) + async def profileConnected( # pylint: disable=invalid-name self, client: SatXMPPClient @@ -1058,7 +1061,7 @@ @param profile: The profile this event belongs to. """ - client = self.__sat.getClient(profile) + client = self.host.getClient(profile) sender = cast(jid.JID, items_event.sender) items = cast(List[domish.Element], items_event.items) @@ -1156,7 +1159,7 @@ @return: The set of public keys available for this JID. """ - gpg_provider = get_gpg_provider(self.__sat, client) + gpg_provider = get_gpg_provider(self.host, client) return gpg_provider.list_public_keys(f"xmpp:{jid.userhost()}") @@ -1167,7 +1170,7 @@ @return: The set of secret keys available for this JID. """ - gpg_provider = get_gpg_provider(self.__sat, client) + gpg_provider = get_gpg_provider(self.host, client) return gpg_provider.list_secret_keys(f"xmpp:{client.jid.userhost()}") @@ -1180,7 +1183,7 @@ @return: The new key. """ - gpg_provider = get_gpg_provider(self.__sat, client) + gpg_provider = get_gpg_provider(self.host, client) secret_key = gpg_provider.create_key(f"xmpp:{client.jid.userhost()}") @@ -1308,7 +1311,7 @@ @return: The ```` element. """ - gpg_provider = get_gpg_provider(self.__sat, client) + gpg_provider = get_gpg_provider(self.host, client) # TODO: I'm not sure whether we want to sign with all keys by default or choose # just one key/a subset of keys to sign with. @@ -1369,7 +1372,7 @@ the calling code. """ - gpg_provider = get_gpg_provider(self.__sat, client) + gpg_provider = get_gpg_provider(self.host, client) decryption_keys = set(filter( lambda secret_key: gpg_provider.can_encrypt(secret_key.public_key), @@ -1457,7 +1460,7 @@ @raise XMPPInteractionFailed: if any interaction via XMPP failed. """ - gpg_provider = get_gpg_provider(self.__sat, client) + gpg_provider = get_gpg_provider(self.host, client) packet = gpg_provider.export_public_key(public_key) @@ -1561,7 +1564,7 @@ @raise XMPPInteractionFailed: if any interaction via XMPP failed. """ - gpg_provider = get_gpg_provider(self.__sat, client) + gpg_provider = get_gpg_provider(self.host, client) node = f"urn:xmpp:openpgp:0:public-keys:{fingerprint}" @@ -1738,7 +1741,7 @@ """ try: - infos = cast(DiscoInfo, await self.__sat.memory.disco.getInfos( + infos = cast(DiscoInfo, await self.host.memory.disco.getInfos( client, client.jid.userhostJID() )) @@ -1813,7 +1816,7 @@ @raise XMPPInteractionFailed: if any interaction via XMPP failed. """ - gpg_provider = get_gpg_provider(self.__sat, client) + gpg_provider = get_gpg_provider(self.host, client) await self.__prepare_secret_key_synchronization(client) @@ -1901,7 +1904,7 @@ @raise DecryptionFailed: on decryption failure. """ - gpg_provider = get_gpg_provider(self.__sat, client) + gpg_provider = get_gpg_provider(self.host, client) return gpg_provider.restore_secret_keys(gpg_provider.decrypt_symmetrically( ciphertext, @@ -2045,7 +2048,7 @@ return {} - submit_id = self.__sat.registerCallback(callback, with_data=True, one_shot=True) + submit_id = self.host.registerCallback(callback, with_data=True, one_shot=True) result = xml_tools.XMLUI( panel_type=C.XMLUI_FORM,