Skip to content

fix(ospf): rebuild cryptographic authentication from its dict form (#1464) - #1469

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1464-ospf-auth-dict
Oct 9, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1464-ospf-auth-dict

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

Closes #1464

to_dict() flattens the AuType 2 auth field (a CryptographicAuthentication info) into a plain dict. from_dict() cannot restore it, because the field is declared bytes | CryptographicAuthentication. _make_encrypt_auth now accepts that dict. A missing reserved defaults to zero, and any other missing key raises ProtocolError.

AuType object form dict form, before → after
0, 1, 7, 65535 exact exact → exact
2 (incl. non-zero reserved) exact ProtocolError: invalid type for auth_data → exact

Sweep: the dict-form rebuild of every edge-harness case and every option-generator case is exact. Only OSPF has a top-level nested info that from_dict leaves as a dict. HIP HostIDParameter.hi and Locator.locator are typed the same way, but they sit inside the parameter list, which to_dict does not flatten, so from_data never hands them a dict.

Tests: the new module passes 6 tests and 16 subtests; without the fix, 3 tests and 3 subtests fail. Also passing: the protocols --exclude protocols/internet leg (1158 tests, OK), test_capture_roundtrip_runtime.py (4 passed), the four *_edge_roundtrip_unit.py modules, and tests/project (419 passed, 1 skipped).

…1464)

to_dict() flattens the AuType 2 auth field, a CryptographicAuthentication
info, into a plain dict, and from_dict() cannot restore it because the field
is declared bytes | CryptographicAuthentication. _make_encrypt_auth now
accepts that dict (reserved defaulting to zero, a missing key refused with
ProtocolError), so OSPF.from_data(info.to_dict()) rebuilds byte for byte
for every AuType.
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 9, 2026
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) review: pending No verdict for the current head - never reviewed, or the head moved since the last one review: running A cross-review is in flight against the current head - no verdict yet and removed review: pending No verdict for the current head - never reviewed, or the head moved since the last one labels Oct 9, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Verdict: GOOD TO GO at 7fc3b9bde (Sonnet cross-review; the author ran on Opus).

  • Dict-form rebuild is exact for all 162 OSPF packets tried, versus 144 failing on main. They cover AuType 2 with 4 reserved, 3 key_id, 4 len and 3 seq values, plus AuTypes 0, 1, 3, 7, 255 and 65535. The same holds for six Ethernet/IPv4/OSPF frames, in both info and dict form. I re-ran the issue repro myself on this head, and it is exact.
  • The reserved default (0000) only affects hand-built dicts. to_dict() always emits the key. A missing key_id, len or seq raises an in-library ProtocolError that names the missing key.
  • The author's HIP claim holds. HIP.from_data(info.to_dict()) is exact for HOST_ID and LOCATOR_SET.
  • The tests fail without the fix. With ospf.py from main, 3 subtests fail, all AuType 2.
  • Legs pass: rest 1158 OK, all four edge modules, capture roundtrip at 20501 subtests, and tests/project.

Nit, no change needed. A wrong value type in the dict, such as key_id='x', raises a raw TypeError from struct. The object form behaves the same way.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Coverage: 89.56% (unit tier, Python 3.14, 7fc3b9bde, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18795 957 2356 870 91.00%
pcapkit/corekit 2043 89 636 25 94.77%
pcapkit/dumpkit 242 2 88 2 98.79%
pcapkit/foundation 2648 98 930 48 94.80%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 16900 222 4564 187 98.06%
pcapkit/toolkit 539 74 168 3 84.58%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2342 1006 157 43.25%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit 3180d41 into main Oct 9, 2026
43 checks passed
@JarryShaw
JarryShaw deleted the fix/1464-ospf-auth-dict branch October 9, 2026 13:17
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(ospf): from_data(info.to_dict()) raises for cryptographic authentication

1 participant