summaryrefslogtreecommitdiff
path: root/tools/integrity.py
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-06-04 19:27:53 +0200
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-06-04 19:27:53 +0200
commite305754990234619d2c870b517555d99e4717522 (patch)
tree99936ea5be9cb8cff724ec42a983b01c4350e1bd /tools/integrity.py
parentf3e792825a78008eb46b5fe01ca5580507cd99c7 (diff)
Refer to ASL using archives
Diffstat (limited to 'tools/integrity.py')
-rw-r--r--tools/integrity.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/integrity.py b/tools/integrity.py
new file mode 100644
index 0000000..e1b2572
--- /dev/null
+++ b/tools/integrity.py
@@ -0,0 +1,34 @@
+import sys
+import hashlib
+import base64
+from pathlib import Path
+import requests
+
+def file_hash(file_path: Path) -> str:
+ sha256_hash = hashlib.sha256()
+ with open(file_path, "rb") as file:
+ while True:
+ data = file.read(65536)
+ if not data:
+ break
+ sha256_hash.update(data)
+ return "sha256-" + base64.b64encode(sha256_hash.digest()).decode()
+
+def url_hash(url: str) -> str:
+ sha256_hash = hashlib.sha256()
+ with requests.get(url, stream=True) as resp:
+ resp.raise_for_status()
+ while True:
+ data = resp.raw.read(65536)
+ if not data:
+ break
+ sha256_hash.update(data)
+ return "sha256-" + base64.b64encode(sha256_hash.digest()).decode()
+
+if __name__ == "__main__" and len(sys.argv) > 1:
+ path = Path(sys.argv[1])
+ if path.exists():
+ print(file_hash(path))
+ else:
+ print(url_hash(sys.argv[1]))
+