Package the adapter SDK boundary and runtime lifecycle. Confirm admitted CAN transactions, bound retained data and test failure paths with synthetic hardware.
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""Fetch the exact reviewed SDK; never execute vendor examples."""
|
|
|
|
import hashlib
|
|
import io
|
|
import json
|
|
import urllib.request
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def fetch():
|
|
lock = json.loads((ROOT / "packaging/sdk-lock.json").read_text())
|
|
with urllib.request.urlopen(lock["url"], timeout=30) as response:
|
|
data = response.read(lock["bytes"] + 1)
|
|
if len(data) != lock["bytes"] or hashlib.sha256(data).hexdigest() != lock["sha256"]:
|
|
raise ValueError("Vendor SDK differs from the reviewed lock")
|
|
with zipfile.ZipFile(io.BytesIO(data)) as archive:
|
|
content = archive.read(lock["library_member"])
|
|
if len(content) != lock["library_bytes"] or content[:6] != b"\x7fELF\x02\x01":
|
|
raise ValueError("Expected the pinned 64-bit little-endian ELF")
|
|
target = ROOT / "build/sdk"
|
|
target.mkdir(parents=True, exist_ok=True)
|
|
(target / "libcontrolcanfd.so").write_bytes(content)
|
|
result = {
|
|
"file": "libcontrolcanfd.so",
|
|
"bytes": len(content),
|
|
"sha256": hashlib.sha256(content).hexdigest(),
|
|
"source_sha256": lock["sha256"],
|
|
}
|
|
(target / "manifest.json").write_text(json.dumps(result, indent=2) + "\n")
|
|
for name in ("controlcanfd.h", "config.h", "main.cpp"):
|
|
(target / name).write_bytes(archive.read("USB-CAN-FD-B-Linux/VMware/x86-c/" + name))
|
|
print(json.dumps(result))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
fetch()
|