Skip to content

Commit 5b1aead

Browse files
igor-holtCopilot
andauthored
Update constellation.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Igor Holt <iholt@mymail.aacc.edu>
1 parent ccc35cb commit 5b1aead

1 file changed

Lines changed: 39 additions & 5 deletions

File tree

src/a2a_ingest/constellation.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,50 @@ def retrieve_body(self, integrity_hash: str) -> Optional[ConstellationRecord]:
4848
encrypted_blob = self._dht.get(integrity_hash)
4949
if not encrypted_blob:
5050
return None
51-
body = self._body_from_payload(encrypted_blob["body"])
52-
recalculated_hash = self.compute_integrity_hash(body)
51+
if not isinstance(encrypted_blob, dict):
52+
return ConstellationRecord(
53+
integrity_hash=integrity_hash,
54+
record_payload={},
55+
signature="",
56+
public_key=None,
57+
status=CORRUPTION_MARKER,
58+
recalculated_hash=None,
59+
)
60+
61+
body_payload = encrypted_blob.get("body")
62+
signature = encrypted_blob.get("signature")
63+
public_key = encrypted_blob.get("public_key")
64+
if not isinstance(body_payload, dict) or not isinstance(signature, str):
65+
return ConstellationRecord(
66+
integrity_hash=integrity_hash,
67+
record_payload=encrypted_blob,
68+
signature=signature if isinstance(signature, str) else "",
69+
public_key=public_key if isinstance(public_key, str) or public_key is None else None,
70+
status=CORRUPTION_MARKER,
71+
recalculated_hash=None,
72+
)
73+
74+
try:
75+
body = self._body_from_payload(body_payload)
76+
recalculated_hash = self.compute_integrity_hash(body)
77+
except (KeyError, TypeError, ValueError):
78+
return ConstellationRecord(
79+
integrity_hash=integrity_hash,
80+
record_payload=encrypted_blob,
81+
signature=signature,
82+
public_key=public_key if isinstance(public_key, str) or public_key is None else None,
83+
status=CORRUPTION_MARKER,
84+
recalculated_hash=None,
85+
)
86+
5387
status = "ANCHOR_OK"
5488
if recalculated_hash != integrity_hash:
5589
status = CORRUPTION_MARKER
5690
return ConstellationRecord(
5791
integrity_hash=integrity_hash,
58-
encrypted_blob=encrypted_blob,
59-
signature=encrypted_blob["signature"],
60-
public_key=encrypted_blob.get("public_key"),
92+
record_payload=encrypted_blob,
93+
signature=signature,
94+
public_key=public_key if isinstance(public_key, str) or public_key is None else None,
6195
status=status,
6296
recalculated_hash=recalculated_hash,
6397
)

0 commit comments

Comments
 (0)