Take input when started as the main module
The encoding method that's used is kinda annoying because the data_dir tree is unreadable. Probably urlencode would have been better.. but now we'd need to migrate everything. This provides a quick way to get a JID converted to what we use as encoding. Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
ec5d502f24
commit
17318815db
1 changed files with 18 additions and 6 deletions
|
@ -28,10 +28,18 @@ from slixmpp.exceptions import IqError, IqTimeout
|
|||
from slixmpp_omemo import PluginCouldNotLoad, MissingOwnKey, NoAvailableSession
|
||||
from slixmpp_omemo import UndecidedException, UntrustedException, EncryptionPrepareException
|
||||
import slixmpp_omemo
|
||||
from pathlib import Path
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def jid_as_path(jid: JID) -> Path:
|
||||
"""Ensure JID in folder names don't contain illegal chars for the FS"""
|
||||
jid_str = jid.bare.encode('utf-8')
|
||||
digest = hashlib.sha256(jid_str).digest()
|
||||
return Path(base64.b32encode(digest).decode('US-ASCII'))
|
||||
|
||||
|
||||
class Plugin(E2EEPlugin):
|
||||
"""OMEMO (XEP-0384) Plugin"""
|
||||
|
||||
|
@ -70,12 +78,11 @@ class Plugin(E2EEPlugin):
|
|||
|
||||
self.info = lambda i: self.api.information(i, 'Info')
|
||||
|
||||
# Ensure folder names don't contain illegal chars for the FS
|
||||
jid_str = self.core.xmpp.boundjid.bare.encode('utf-8')
|
||||
digest = hashlib.sha256(jid_str).digest()
|
||||
hashed_jid = base64.b32encode(digest).decode('US-ASCII')
|
||||
|
||||
data_dir = os.path.join(DATA_HOME, 'omemo', hashed_jid)
|
||||
data_dir = os.path.join(
|
||||
DATA_HOME,
|
||||
'omemo',
|
||||
jid_as_path(self.core.xmpp.boundjid),
|
||||
)
|
||||
|
||||
try:
|
||||
# Raise exception if folder exists so that we don't chmod again.
|
||||
|
@ -228,3 +235,8 @@ class Plugin(E2EEPlugin):
|
|||
return None
|
||||
|
||||
return None
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
jid = JID(input('JID: '))
|
||||
print(jid_as_path(jid))
|
||||
|
|
Loading…
Reference in a new issue