Skip to content

Commit 403c936

Browse files
Prevent undetected modifications via HMAC integrity checks
1 parent 9eff90b commit 403c936

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pydatastructs/graphs/graph.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ def get_snapshot(self, timestamp: int):
139139
stored_signature = snapshot_info["signature"]
140140
snapshot_data = serialize_graph(snapshot_graph)
141141
computed_signature = generate_hmac(snapshot_data)
142-
142+
if computed_signature != stored_signature:
143+
raise ValueError("Snapshot integrity check failed! The snapshot may have been modified.")
144+
return snapshot_graph
143145
def list_snapshots(self):
144146
"""Returns all stored timestamps in sorted order."""
145147
return sorted(self.snapshots.keys())

0 commit comments

Comments
 (0)