summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2019-08-25 01:39:59 +0200
committerMaxime “pep” Buquet <pep@bouah.net>2019-12-27 18:58:48 +0100
commit518ba47e2aaea628e38132a826101a8c17801a79 (patch)
tree4be1b118969bb306c015173a8399b5728c405113
parent5c4571751ec790f9788e558d9c40017ef872b862 (diff)
downloadpoezio-518ba47e2aaea628e38132a826101a8c17801a79.tar.gz
poezio-518ba47e2aaea628e38132a826101a8c17801a79.tar.bz2
poezio-518ba47e2aaea628e38132a826101a8c17801a79.tar.xz
poezio-518ba47e2aaea628e38132a826101a8c17801a79.zip
omemo: add an api in plugin_e2ee to get the fingerprint(s) of a jid
-rw-r--r--poezio/plugin_e2ee.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/poezio/plugin_e2ee.py b/poezio/plugin_e2ee.py
index 910e3d01..fde7f10c 100644
--- a/poezio/plugin_e2ee.py
+++ b/poezio/plugin_e2ee.py
@@ -178,6 +178,14 @@ class E2EEPlugin(BasePlugin):
help=trust_msg.format(name=self.encryption_short_name, state=state),
)
+ self.api.add_command(
+ self.encryption_short_name + '_fingerprint',
+ self._command_show_fingerprints,
+ usage='[jid]',
+ short='Show %s fingerprint(s) for a JID.' % self.encryption_short_name,
+ help='Show %s fingerprint(s) for a JID.' % self.encryption_short_name,
+ )
+
ConversationTab.add_information_element(
self.encryption_short_name,
self._display_encryption_status,
@@ -238,6 +246,33 @@ class E2EEPlugin(BasePlugin):
'Info',
)
+ def _show_fingerprints(self, jid: JID) -> None:
+ """Display encryption fingerprints for a JID."""
+ fprs = self.get_fingerprints(jid)
+ if len(fprs) == 1:
+ self.api.information(
+ 'Fingerprint for %s: %s' % (jid, fprs[0]),
+ 'Info',
+ )
+ elif fprs:
+ self.api.information(
+ 'Fingerprints for %s:\n\t%s' % (jid, '\n\t'.join(fprs)),
+ 'Info',
+ )
+ else:
+ self.api.information(
+ 'No fingerprints to display',
+ 'Info',
+ )
+
+ @command_args_parser.quoted(0, 1)
+ def _command_show_fingerprints(self, args: List[str]) -> None:
+ if not args and isinstance(self.api.current_tab(), self.supported_tab_types):
+ jid = self.api.current_tab().name
+ else:
+ jid = args[0]
+ self._show_fingerprints(jid)
+
@command_args_parser.quoted(2)
def __command_set_state_global(self, args, state='') -> None:
jid, fpr = args
@@ -422,3 +457,12 @@ class E2EEPlugin(BasePlugin):
"""
raise NotImplementedError
+
+ def get_fingerprints(self, jid: JID) -> List[str]:
+ """Show fingerprint(s) for this encryption method and JID.
+
+ To overload in plugins.
+
+ :returns: A list of fingerprints to display
+ """
+ return []