(file, blocksize=65536, format="hexdigest")
| 4 | |
| 5 | |
| 6 | def sha512sum(file, blocksize=65536, format="hexdigest"): |
| 7 | if type(file) is str: # Filename specified |
| 8 | file = open(file, "rb") |
| 9 | hash = hashlib.sha512() |
| 10 | for block in iter(lambda: file.read(blocksize), b""): |
| 11 | hash.update(block) |
| 12 | |
| 13 | # Truncate to 256bits is good enough |
| 14 | if format == "hexdigest": |
| 15 | return hash.hexdigest()[0:64] |
| 16 | else: |
| 17 | return hash.digest()[0:32] |
| 18 | |
| 19 | |
| 20 | def sha256sum(file, blocksize=65536): |