Change to Python3 coding style
This commit is contained in:
parent
fc0fe0557b
commit
b0b9a4d33c
137 changed files with 910 additions and 913 deletions
|
@ -13,10 +13,10 @@ def sha1sum(file, blocksize=65536):
|
|||
|
||||
|
||||
def sha512sum(file, blocksize=65536, format="hexdigest"):
|
||||
if hasattr(file, "endswith"): # Its a string open it
|
||||
if type(file) is str: # Filename specified
|
||||
file = open(file, "rb")
|
||||
hash = hashlib.sha512()
|
||||
for block in iter(lambda: file.read(blocksize), ""):
|
||||
for block in iter(lambda: file.read(blocksize), b""):
|
||||
hash.update(block)
|
||||
|
||||
# Truncate to 256bits is good enough
|
||||
|
@ -31,7 +31,7 @@ def sha256sum(file, blocksize=65536):
|
|||
if hasattr(file, "endswith"): # Its a string open it
|
||||
file = open(file, "rb")
|
||||
hash = hashlib.sha256()
|
||||
for block in iter(lambda: file.read(blocksize), ""):
|
||||
for block in iter(lambda: file.read(blocksize), b""):
|
||||
hash.update(block)
|
||||
return hash.hexdigest()
|
||||
|
||||
|
@ -39,7 +39,7 @@ def sha256sum(file, blocksize=65536):
|
|||
def random(length=64, encoding="hex"):
|
||||
if encoding == "base64": # Characters: A-Za-z0-9
|
||||
hash = hashlib.sha512(os.urandom(256)).digest()
|
||||
return base64.standard_b64encode(hash).replace("+", "").replace("/", "").replace("=", "")[0:length]
|
||||
return base64.b64encode(hash).decode("ascii").replace("+", "").replace("/", "").replace("=", "")[0:length]
|
||||
else: # Characters: a-f0-9 (faster)
|
||||
return hashlib.sha512(os.urandom(256)).hexdigest()[0:length]
|
||||
|
||||
|
|
|
@ -35,4 +35,4 @@ def privatekeyToPublickey(privatekey):
|
|||
return pub.save_pkcs1("DER")
|
||||
|
||||
def publickeyToOnion(publickey):
|
||||
return base64.b32encode(hashlib.sha1(publickey).digest()[:10]).lower()
|
||||
return base64.b32encode(hashlib.sha1(publickey).digest()[:10]).lower().decode("ascii")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue