Skip to content

refactor(protocols): finish the shared value helpers on ProtocolBase and move TLS onto them - #2638

Merged
JarryShaw merged 1 commit into
mainfrom
refactor/2614-protocol-helpers
Nov 2, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
refactor/2614-protocol-helpers

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • refactor — changes neither behaviour nor performance

Description of your pull request and other information

This finishes the shared value helpers on ProtocolBase from #2614's audit, and moves TLS onto them.

New helpers: _read_octets, _read_uint, _read_sint/_make_sint, _uint_size, _make_octets, _read_mac_addr/_make_mac_addr, _read_text, and alias= on _make_uint.

Adoption:

  • TLS: drops its module-level _take. Every TLS hello, handshake, content and record-header maker packs through _make_pack, so an oversize value raises StructError: TLS: pack failed instead of wrapping or leaking a bare error. TLS and DTLS are not in any release.
  • Ethernet: uses the base MAC helpers.
  • PCAP-NG and 802.11: keep only the overrides that change behaviour.
  • OSPF: checks packet_length with _make_uint(alias='OSPF').
  • SCTP: the fix(protocols): makers reject bad arguments with the reader's 'invalid format' text #2296-pinned flag and cause makers use _make_octets.

Owner ruling (3): the member-order page's worked example and reference class move to ARP, so Ethernet loses its delegate and pylint pragma.

Changed messages:

  • SCTP: [Chunk 132] invalid flags: must be one octet, not b'' → SCTP: invalid [Chunk 132] flags: must be 1 octet, not b''
  • SCTP: [Cause 1] invalid reserved: must be two octets, not b'' → SCTP: invalid [Cause 1] reserved: must be 2 octets, not b''

The owner accepted these re-pins when choosing _make_octets.

Verification:

  • Valid output is byte-identical across a 20,590-case TLS differential and 31,536 MAC maker calls.
  • The new tests fail on main.
  • A Sonnet cross-review's findings are folded in.

Part of #2614

@JarryShaw JarryShaw added this to the PyPCAPKit v1.6 milestone Nov 2, 2026
@JarryShaw JarryShaw added refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix) review: good-to-go Cross-review at the current head says ready; CI state is separate labels Nov 2, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at c82e1b62c. A Sonnet cross-review differential-checked each new helper against the copies it replaces, with 0 diffs:

  • 4,210 MAC inputs across Ethernet, PCAP-NG MAC/EUI, 802.11 and ARP;
  • 2,019 text samples;
  • 5,218 signed values;
  • 270,000 _uint_size cases.

It also ran 6,625 TLS/DTLS parse/build cases. The only differences are oversize makes, which now raise StructError.

Its NEEDS CHANGES round is folded in:

  • dead PAT_MAC_ADDR deleted;
  • ARP is the member-order reference, per ruling 3, so Ethernet drops its pragma'd delegate;
  • the TLS record header refuses oversize values;
  • the _read_text error arm is tested.

The two re-pinned SCTP messages are listed in the description.

@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 2, 2026
…o them (#2614)

- ProtocolBase: add _read_octets, _read_uint, _read_sint, _read_mac_addr,
  _read_text, _make_octets, _make_sint, _uint_size and _make_mac_addr;
  _read_vector reads through them and _make_uint takes alias=.
- Ethernet uses the base MAC pair, and its dead PAT_MAC_ADDR goes, as does
  PCAP-NG's; PCAP-NG and 802.11 keep only the overrides that change behaviour.
- protocol-member-order.rst: ARP is the worked example and the reference.
- TLS: drop _take, with octets and messages unchanged; every maker and the
  record header pack through _make_pack, so an oversize value is StructError.
- SCTP: chunk flags and invalid-stream reserved use _make_octets, naming the
  chunk or cause in name=; OSPF.make checks packet_length with _make_uint.

TLS/DTLS/SSL, link, helper, #2296 and member-order tests pass.
@JarryShaw
JarryShaw force-pushed the refactor/2614-protocol-helpers branch from c82e1b6 to 0d23b5e Compare November 2, 2026 07:00
@JarryShaw

Copy link
Copy Markdown
Owner Author

Rebased onto main (18544c3c9): c82e1b62c → 0d23b5e3a. No conflicts. The stable patch-id 4972ab103a42 is identical, and range-diff reports =, so the patch is unchanged and the verdict stays good-to-go. The rebase brings in #2637, which fixes the red Python pypy3.11 leg. The remaining test_package_reexports_1807_unit failure is on main and is fixed in #2641.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Coverage: 94.08% -- tests failure, so this is partial (unit tier, Python 3.15, 0d23b5e3a, Unit Tests run failure)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 20561 177 2832 158 98.53%
pcapkit/corekit 2697 74 854 37 96.65%
pcapkit/dumpkit 281 3 100 3 98.43%
pcapkit/foundation 3475 27 1206 32 98.74%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 21394 218 5626 196 98.45%
pcapkit/toolkit 961 28 342 10 96.32%
pcapkit/utilities 512 7 144 5 98.17%
pcapkit/vendor 5256 2260 1198 194 53.61%

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

@JarryShaw

Copy link
Copy Markdown
Owner Author

The red Python 3.15 leg comes from this PR's base, not its change. It fails only the DTLSCIDCiphertext schema round trip, which main fixed in 16ccc4373 (#2645), and the re-export test that #2641 fixes. I'll rebase once #2641 merges. The verdict stays good to go.

@JarryShaw
JarryShaw merged commit b731a7b into main Nov 2, 2026
59 of 61 checks passed
@JarryShaw
JarryShaw deleted the refactor/2614-protocol-helpers branch November 2, 2026 14:37
@JarryShaw JarryShaw moved this from In review to Done in PyPCAPKit Nov 2, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 2, 2026
JarryShaw added a commit that referenced this pull request Nov 2, 2026
…shared value helpers into 1.6.0 (#2449)

- Breaking: NoPayload and its data model and schema move from misc.null to
  misc.no_payload with no re-export, so a frame pickled by 1.5.x fails to
  load (#2636). 1.5.0's three NoPayload roles and 1.6.0's own point at
  misc.no_payload, 1.5.0's text unchanged.
- Added: the IP, L2TP, ICMP, IGMP and LinuxSLL bases give a member on read,
  make and from_data, version= naming it, with the refusals and IPv4's
  Version check ahead of the header (#2639).
- Changed: SCTP's chunk-flag and Invalid Stream Identifier reserved-octet
  messages (#2638). Folded into the TLS/DTLS entry: make() raises
  StructError for a value too wide for its field (#2638), and the
  DTLS_CIDCiphertext and TLS_ConnectionId package exports (#2641).
- The conventions entry records the version= dispatch rule (#2639) and ARP
  as the member-order reference (#2638).
- No entry for #2638's private value helpers or the Ethernet and PCAP-NG
  PAT_MAC_ADDR, as for #1844's OSPF copy; #2640's docstring fixes; or the
  test-only #2620, #2637, #2645 and #2646.
- CHANGELOG.md regenerated; util/changelog_md.py --check passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant