Recover kit checksums from a truncated Sox schema reply
The device builds the schema and version replies in a fixed 512-byte packet and drops whatever does not fit. Read strings defensively, recover a cut-off checksum from the one local manifest matching its prefix, and fail with a clear message when the kit list cannot be recovered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -224,9 +224,32 @@ def find_manifest_path(kit_name, checksum):
|
||||
return None
|
||||
|
||||
|
||||
def resolve_truncated_checksum(kit_name, prefix):
|
||||
"""The checksum of the one local manifest whose leading bytes match ``prefix``.
|
||||
|
||||
Used when a device's schema reply cut a kit's checksum short. Returns the
|
||||
checksum as a signed 32-bit int (as read off the wire), or None when no
|
||||
manifest, or more than one, matches.
|
||||
"""
|
||||
manifest_dir = os.path.join(app_state.SEDONA_HOME, "manifests", kit_name)
|
||||
if not os.path.isdir(manifest_dir):
|
||||
return None
|
||||
want = prefix.hex()
|
||||
matches = set()
|
||||
for f in os.listdir(manifest_dir):
|
||||
if f.startswith(f"{kit_name}-") and f.endswith(".xml"):
|
||||
hex_part = f[len(kit_name) + 1:-4].zfill(8).lower()
|
||||
if hex_part.startswith(want):
|
||||
matches.add(hex_part)
|
||||
if len(matches) != 1:
|
||||
return None
|
||||
value = int(matches.pop(), 16)
|
||||
return value - (1 << 32) if value & 0x80000000 else value
|
||||
|
||||
|
||||
def find_manifest(kit_name, checksum):
|
||||
"""Returns the parsed ET root of a kit manifest, or None."""
|
||||
checksum_hex = f"{checksum:08x}" if isinstance(checksum, int) else checksum
|
||||
checksum_hex = f"{checksum & 0xFFFFFFFF:08x}" if isinstance(checksum, int) else checksum
|
||||
path = find_manifest_path(kit_name, checksum_hex)
|
||||
if path is None:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user