Commit fdd15e44 authored by Philipp Hörist's avatar Philipp Hörist

Refactor get_random_string()

parent 6730e814
......@@ -21,7 +21,7 @@ from gi.repository import Gio
from gajim.common import configpaths
from gajim.common.helpers import get_random_string_16
from gajim.common.helpers import get_random_string
from gajim.common.helpers import write_file_async
......@@ -36,7 +36,7 @@ class CertificateStore:
self._load_certificates()
def _get_random_path(self):
filename = get_random_string_16()
filename = get_random_string()
path = self._path / filename
if path.exists():
return self._get_random_path()
......
......@@ -798,15 +798,14 @@ def remove_invalid_xml_chars(string_):
string_ = re.sub(app.interface.invalid_XML_chars_re, '', string_)
return string_
def get_random_string_16():
def get_random_string(count=16):
"""
Create random string of length 16
Create random string of count length
WARNING: Don't use this for security purposes
"""
rng = list(range(65, 90))
rng.extend(range(48, 57))
char_sequence = [chr(e) for e in rng]
from random import sample
return ''.join(sample(char_sequence, 16))
allowed = string.ascii_uppercase + string.digits
return ''.join(random.choice(allowed) for char in range(count))
def get_os_info():
if app.os_info:
......
......@@ -215,7 +215,7 @@ class Jingle(BaseModule):
senders=senders)
file_props.transport_sid = transport.sid
file_props.algo = self.__hash_support(contact)
jingle.add_content('file' + helpers.get_random_string_16(), transfer)
jingle.add_content('file' + helpers.get_random_string(), transfer)
jingle.start_session()
return transfer.transport.sid
......
......@@ -233,7 +233,7 @@ class ProxyResolver:
self.jid = None
self.host = None
self.port = None
self.sid = helpers.get_random_string_16()
self.sid = helpers.get_random_string()
self.sender_jid = sender_jid
self.testit = testit
......
......@@ -310,7 +310,7 @@ class FileTransfersWindow:
account, jid)
fjid = contact.get_full_jid()
# Request the file to the sender
sid = helpers.get_random_string_16()
sid = helpers.get_random_string()
new_file_props = FilesProp.getNewFileProp(account, sid)
new_file_props.file_name = file_props.file_name
new_file_props.name = file_props.name
......@@ -721,7 +721,7 @@ class FileTransfersWindow:
_('It is not possible to send empty files'))
return None
file_props = FilesProp.getNewFileProp(
account, sid=helpers.get_random_string_16())
account, sid=helpers.get_random_string())
mod_date = os.path.getmtime(file_path)
file_props.file_name = file_path
file_props.name = file_name
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment