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 PluginCouldNotLoad, MissingOwnKey, NoAvailableSession
|
||||||
from slixmpp_omemo import UndecidedException, UntrustedException, EncryptionPrepareException
|
from slixmpp_omemo import UndecidedException, UntrustedException, EncryptionPrepareException
|
||||||
import slixmpp_omemo
|
import slixmpp_omemo
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
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):
|
class Plugin(E2EEPlugin):
|
||||||
"""OMEMO (XEP-0384) Plugin"""
|
"""OMEMO (XEP-0384) Plugin"""
|
||||||
|
|
||||||
|
@ -70,12 +78,11 @@ class Plugin(E2EEPlugin):
|
||||||
|
|
||||||
self.info = lambda i: self.api.information(i, 'Info')
|
self.info = lambda i: self.api.information(i, 'Info')
|
||||||
|
|
||||||
# Ensure folder names don't contain illegal chars for the FS
|
data_dir = os.path.join(
|
||||||
jid_str = self.core.xmpp.boundjid.bare.encode('utf-8')
|
DATA_HOME,
|
||||||
digest = hashlib.sha256(jid_str).digest()
|
'omemo',
|
||||||
hashed_jid = base64.b32encode(digest).decode('US-ASCII')
|
jid_as_path(self.core.xmpp.boundjid),
|
||||||
|
)
|
||||||
data_dir = os.path.join(DATA_HOME, 'omemo', hashed_jid)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Raise exception if folder exists so that we don't chmod again.
|
# Raise exception if folder exists so that we don't chmod again.
|
||||||
|
@ -228,3 +235,8 @@ class Plugin(E2EEPlugin):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
jid = JID(input('JID: '))
|
||||||
|
print(jid_as_path(jid))
|
||||||
|
|
Loading…
Reference in a new issue