[PATCH] D68104: [LNT] Python 3 support: adapt secret computation
Thomas Preud'homme via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 14:33:54 PDT 2019
thopre created this revision.
thopre added reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls.
Computation of the secret when it is not supplied on the command line
involves passing a string constructed with str to the sha1 function
which expects binary data. However in Python3 a string is not considered
binary data so this line gives an error.
This commit replaces the computation logic to use the one used by the
secrets module of Python 3.6+, namely calling binascii.hexlify and
os.urandom which behaves consistently between Python 2 and 3.
https://reviews.llvm.org/D68104
Files:
lnt/lnttool/create.py
Index: lnt/lnttool/create.py
===================================================================
--- lnt/lnttool/create.py
+++ lnt/lnttool/create.py
@@ -114,13 +114,12 @@
LNT configuration.
"""
from .common import init_logger
- import hashlib
+ import binascii
import lnt.server.db.migrate
import lnt.server.db.util
import lnt.testing
import logging
import os
- import random
import sys
init_logger(logging.INFO if show_sql else logging.WARNING,
@@ -138,7 +137,7 @@
wsgi_path = os.path.join(basepath, wsgi)
schemas_path = os.path.join(basepath, "schemas")
secret_key = (secret_key or
- hashlib.sha1(str(random.getrandbits(256))).hexdigest())
+ binascii.hexlify(os.urandom(20)).decode('ascii'))
os.mkdir(instance_path)
os.mkdir(tmp_path)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68104.222027.patch
Type: text/x-patch
Size: 855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190926/6e38ae36/attachment.bin>
More information about the llvm-commits
mailing list