Replace SHA1 with hex(length) + sha512

This commit is contained in:
2014-12-11 16:27:05 +01:00
parent c322c30fe5
commit 81908c8b5d
4 changed files with 28 additions and 14 deletions

View File

@@ -45,13 +45,27 @@ else:
return msg
def sha1_from_file(fn, block_size=1 << 20):
def uuid_from_file(fn, block_size=1 << 20):
"""
Returns an arbitrary sized unique ASCII string based on the file contents.
(exact hashing method may change).
"""
with open(fn, 'rb') as f:
# first get the size
import os
f.seek(0, os.SEEK_END)
size = f.tell()
f.seek(0, os.SEEK_SET)
del os
# done!
import hashlib
sha1 = hashlib.new('sha1')
sha1 = hashlib.new('sha512')
while True:
data = f.read(block_size)
if not data:
break
sha1.update(data)
return sha1.hexdigest()
# skip the '0x'
return hex(size)[2:] + sha1.hexdigest()