From 936371a7ec2aa26c245aa7e0aaef0585d2953efe Mon Sep 17 00:00:00 2001 From: shortcutme Date: Tue, 3 Oct 2017 15:20:50 +0200 Subject: [PATCH] Support digest output for sha512sum --- src/Crypt/CryptHash.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Crypt/CryptHash.py b/src/Crypt/CryptHash.py index fb0c2dab..39459bcc 100644 --- a/src/Crypt/CryptHash.py +++ b/src/Crypt/CryptHash.py @@ -12,13 +12,19 @@ def sha1sum(file, blocksize=65536): return hash.hexdigest() -def sha512sum(file, blocksize=65536): +def sha512sum(file, blocksize=65536, format="hexdigest"): if hasattr(file, "endswith"): # Its a string open it file = open(file, "rb") hash = hashlib.sha512() for block in iter(lambda: file.read(blocksize), ""): 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):