Skip to content

Commit 6e54936

Browse files
Handle empty graphs in serialization to prevent HMAC errors
1 parent 99fd732 commit 6e54936

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pydatastructs/graphs/graph.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def get_secret_key():
2121
def generate_hmac(data):
2222
"""Generating HMAC signature for integrity verification"""
2323
return hmac.new(get_secret_key(), data.encode(),hashlib.sha256).haxdigit()
24+
def serialize_graph(graph):
25+
"""Converts a graph into a string for HMAC signing."""
26+
if not graph.vertices or not graph.edge_weights:
27+
return "EMPTY_GRAPH"
28+
return str(sorted(graph.vertices)) + str(sorted(graph.edge_weights.items()))
29+
2430
__all__ = [
2531
'Graph'
2632
]

0 commit comments

Comments
 (0)