summaryrefslogtreecommitdiff
path: root/python/build/verify.py
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2016-12-29 21:43:47 +0100
committerMax Kellermann <max@musicpd.org>2016-12-29 21:43:47 +0100
commit79403afbe6f73a199af44892c90e265743f3ad7f (patch)
tree7d6deac6b0e3755dbb5d230e82436255f5f85225 /python/build/verify.py
parent4c650e87fa5cb7d0a85dc6f574bde3bfae59a979 (diff)
python/build/verify: prepare SHA support
Diffstat (limited to 'python/build/verify.py')
-rw-r--r--python/build/verify.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/python/build/verify.py b/python/build/verify.py
index 450b2aece..5082ef521 100644
--- a/python/build/verify.py
+++ b/python/build/verify.py
@@ -23,12 +23,16 @@ def file_digest(algorithm, path):
feed_file_path(h, path)
return h.hexdigest()
-def file_md5(path):
- """Calculate the MD5 checksum of a file and return it in hexadecimal notation."""
-
- return file_digest(hashlib.md5, path)
+def guess_digest_algorithm(digest):
+ l = len(digest)
+ if l == 32:
+ return hashlib.md5
+ else:
+ return None
def verify_file_digest(path, expected_digest):
"""Verify the digest of a file, and return True if the digest matches with the given expected digest."""
- return file_md5(path) == expected_digest
+ algorithm = guess_digest_algorithm(expected_digest)
+ assert(algorithm is not None)
+ return file_digest(algorithm, path) == expected_digest