implement format_fingerprint method
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
b4a03e3034
commit
5a9daa9db7
1 changed files with 27 additions and 0 deletions
|
@ -18,8 +18,10 @@ import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
|
from poezio import colors
|
||||||
from poezio.plugin_e2ee import E2EEPlugin
|
from poezio.plugin_e2ee import E2EEPlugin
|
||||||
from poezio.xdg import DATA_HOME
|
from poezio.xdg import DATA_HOME
|
||||||
|
from poezio.theming import Theme
|
||||||
from poezio.tabs import ChatTab, DynamicConversationTab, StaticConversationTab, MucTab
|
from poezio.tabs import ChatTab, DynamicConversationTab, StaticConversationTab, MucTab
|
||||||
|
|
||||||
from omemo.exceptions import MissingBundleException
|
from omemo.exceptions import MissingBundleException
|
||||||
|
@ -123,6 +125,31 @@ class Plugin(E2EEPlugin):
|
||||||
if trust is not None
|
if trust is not None
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def format_fingerprint(fingerprint: str, theme: Theme) -> str:
|
||||||
|
"""
|
||||||
|
Color fingerprint as specified in in XEP-0384 0.8.3 Ҥ8 Security
|
||||||
|
Considerations”.
|
||||||
|
|
||||||
|
“When displaying the fingerprint as a hex-string, the RECOMMENDED
|
||||||
|
way to make it easier to compare the fingerprint is to split the
|
||||||
|
lowercase hex-string into 8 substrings of 8 chars each, then
|
||||||
|
coloring each group of 8 lowercase hex chars using Consistent
|
||||||
|
Color Generation (XEP-0392)”
|
||||||
|
"""
|
||||||
|
size = len(fingerprint) // 8
|
||||||
|
parts = map(''.join, zip(*[iter(fingerprint)]*8))
|
||||||
|
colored_fp = ''
|
||||||
|
for i, part in enumerate(parts):
|
||||||
|
fg_color = colors.ccg_text_to_color(theme.ccg_palette, part)
|
||||||
|
separator = ' '
|
||||||
|
if i == (size // 2 - 1):
|
||||||
|
separator = '\n'
|
||||||
|
elif i == size - 1:
|
||||||
|
separator = ''
|
||||||
|
colored_fp += f'\x19{fg_color}}}{part}{separator}'
|
||||||
|
return colored_fp
|
||||||
|
|
||||||
async def decrypt(self, message: Message, jid: Optional[JID], tab: ChatTab) -> None:
|
async def decrypt(self, message: Message, jid: Optional[JID], tab: ChatTab) -> None:
|
||||||
if jid is None:
|
if jid is None:
|
||||||
self.display_error('Unable to decrypt the message.')
|
self.display_error('Unable to decrypt the message.')
|
||||||
|
|
Loading…
Reference in a new issue