Eureka2 / utils /hash_utils.py
Bosch09's picture
Upload 15 files
19641b3 verified
Raw History Blame Contribute Delete
837 Bytes
# ============================================================
# utils/hash_utils.py
# ============================================================
import json
import hashlib
def generate_sha256_hash(payload):
"""
Creates a SHA256 hash for audit evidence.
"""
text = json.dumps(
payload,
sort_keys=True,
default=str
)
return hashlib.sha256(
text.encode("utf-8")
).hexdigest()
def generate_dataframe_hash(df):
"""
Creates a stable hash for a dataframe.
Useful for proving result integrity.
"""
if df is None or len(df) == 0:
return generate_sha256_hash({"data": "empty"})
csv_text = df.to_csv(
index=False
)
return hashlib.sha256(
csv_text.encode("utf-8")
).hexdigest()