Support digest output for sha512sum

This commit is contained in:
shortcutme 2017-10-03 15:20:50 +02:00
parent 628cc992e9
commit 936371a7ec
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -12,13 +12,19 @@ def sha1sum(file, blocksize=65536):
return hash.hexdigest() return hash.hexdigest()
def sha512sum(file, blocksize=65536): def sha512sum(file, blocksize=65536, format="hexdigest"):
if hasattr(file, "endswith"): # Its a string open it if hasattr(file, "endswith"): # Its a string open it
file = open(file, "rb") file = open(file, "rb")
hash = hashlib.sha512() hash = hashlib.sha512()
for block in iter(lambda: file.read(blocksize), ""): for block in iter(lambda: file.read(blocksize), ""):
hash.update(block) hash.update(block)
return hash.hexdigest()[0:64] # Truncate to 256bits is good enough
# Truncate to 256bits is good enough
if format == "hexdigest":
return hash.hexdigest()[0:64]
else:
return hash.digest()[0:32]
def sha256sum(file, blocksize=65536): def sha256sum(file, blocksize=65536):