-
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathprint-hash.py
More file actions
26 lines (19 loc) · 646 Bytes
/
print-hash.py
File metadata and controls
26 lines (19 loc) · 646 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import hashlib
import pathlib
import sys
packages_dir = pathlib.Path(sys.argv[1]).resolve()
print('Showing hash values of files to be uploaded:')
for file_object in packages_dir.iterdir():
sha256 = hashlib.sha256()
md5 = hashlib.md5() # noqa: S324; only use for reference
blake2_256 = hashlib.blake2b(digest_size=256 // 8)
print(file_object)
print('')
content = file_object.read_bytes()
sha256.update(content)
md5.update(content)
blake2_256.update(content)
print(f'SHA256: {sha256.hexdigest()}')
print(f'MD5: {md5.hexdigest()}')
print(f'BLAKE2-256: {blake2_256.hexdigest()}')
print('')