You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(protocols): move shared value pack/unpack helpers into the Protocol utilities #2614
The owner asked, in session, for the request on #2595 and #2607 to be applied to shipped code. Paraphrased: value-type pack and unpack helpers belong in the base Protocol's utility methods, where every protocol can share them.
Scope: audit pcapkit/protocols/ on main for helpers that pack or unpack values and that more than one protocol could use, then migrate them into Protocol. That covers module-level functions and per-class methods, such as fixed-width and bit-width unsigned integers, lists of them, length-prefixed vectors, and bitfield packing. Protocol-specific encoders stay where they are, as do helpers that _read_unpack/_make_pack already cover.
Plan:
A read-only audit lists every candidate with its call sites and semantics, and proposes the shared Protocol API. It is in progress.
Audit of shipped code on main (3ccdc3271) for value pack/unpack helpers that belong on the base protocol. Four Sonnet auditors each covered one layer, and a fifth agent verified and deduplicated their findings. Every "move" and a sample of the "covered" verdicts were re-checked against main.
_read_text merges the identical FTP._decode_args and HTTPv1._decode_text.
Optional:_uint_size, which counts the octets an unsigned int needs and is used by HIP, MH and HOPOPT.
Alignment helper: a pad_length helper replaces arithmetic spelled five ways in PCAPNG, HIP, IPv4, the IPv6 options and MH. It is a plain function rather than a method, because schema callbacks cannot call a protocol method. A PaddingField(align=…) option would replace most of the schema lambdas.
Plan. After #2595 merges, the migration runs one commit group per module family. Every group is byte-identical on the regenerated samples and has tests that fail before the change. Groups that share a file land one after another, and the ones that overlap #2607 or #2574 land after those. The open questions are in the next comment. Two findings are split out: the ContextVar question goes to its own issue, and a Quick-Start codec defect gets a bug issue.
Needs deciding before the migration (it starts only after #2595 merges):
Where pad_length lives. (a) pcapkit.corekit.fields.strings, beside PaddingField; (b) a new pcapkit.utilities module. Recommend (a): padding is part of what a schema is built from.
_make_uint turns silent wraps into errors.
Measured on main: TCP window=70000 packs 0x1170, seq_no=-1 packs 0xffffffff, and UDP total_length=70000 packs 0x1170.
The same applies to bool in RPL's reserved field and to negative values in MH and MPL.
Options: (a) raise ProtocolError; (b) keep the wraps.
Recommend (a): a wrapped value builds a different packet from the one asked for. Signed and sentinel PCAP-NG fields, such as section_length=-1, keep masking and get a field-by-field review.
The member-order page's worked example. It uses Ethernet's MAC pair, which moves to the base class. Recommend: the MAC commit picks a replacement class that still carries a full reader/maker pair, and the PR shows it for your review.
_read_sint/_make_sint move to the base class, even though MH is their only user.
Every question is answered. The padding helper (pad_length, with PaddingField(align=…) adopted across the PCAP-NG, SCTP and HIP schemas) does not depend on #2595, so a worker is on it now. The other commit groups use #2595's helpers and are dispatched once it merges.
The owner chose 2, paraphrased. section_length keeps -1 as its "not specified" sentinel and accepts the range from -2**63 to 2**64 - 1, with -1 and 0xFFFFFFFFFFFFFFFF reading back alike. Anything outside that range, and any bool, raises ProtocolError, per #2617. Masking survives only where it maps the signed spelling onto the unsigned one.
This settles the question, so needs: decision comes off. It goes into the PCAP-NG group's commit, with a test for each refused case and for each edge of the range. The drop_count decision recorded above stands.
Activity
JarryShaw commentedon Nov 2, 2026
Audit of shipped code on
main(3ccdc3271) for value pack/unpack helpers that belong on the base protocol. Four Sonnet auditors each covered one layer, and a fifth agent verified and deduplicated their findings. Every "move" and a sample of the "covered" verdicts were re-checked againstmain.Proposed additions to
ProtocolBase:_make_uint, and the vector and uint-list makers._read_octetstakes over TLS's_take._read_uintreplaces the bytes-buffer big-endian reads inssl/tls._read_textmerges the identicalFTP._decode_argsandHTTPv1._decode_text._uint_size, which counts the octets an unsigned int needs and is used by HIP, MH and HOPOPT.pad_lengthhelper replaces arithmetic spelled five ways in PCAPNG, HIP, IPv4, the IPv6 options and MH. It is a plain function rather than a method, because schema callbacks cannot call a protocol method. APaddingField(align=…)option would replace most of the schema lambdas.Plan. After #2595 merges, the migration runs one commit group per module family. Every group is byte-identical on the regenerated samples and has tests that fail before the change. Groups that share a file land one after another, and the ones that overlap #2607 or #2574 land after those. The open questions are in the next comment. Two findings are split out: the ContextVar question goes to its own issue, and a Quick-Start codec defect gets a bug issue.
JarryShaw commentedon Nov 2, 2026
Needs deciding before the migration (it starts only after #2595 merges):
pad_lengthlives. (a)pcapkit.corekit.fields.strings, besidePaddingField; (b) a newpcapkit.utilitiesmodule. Recommend (a): padding is part of what a schema is built from._make_uintturns silent wraps into errors.main: TCPwindow=70000packs0x1170,seq_no=-1packs0xffffffff, and UDPtotal_length=70000packs0x1170.boolin RPL's reserved field and to negative values in MH and MPL.ProtocolError; (b) keep the wraps.section_length=-1, keep masking and get a field-by-field review._make_octets. Adopting it means re-pinning a dozen whole-string error messages from fix(protocols): makers reject bad arguments with the reader's 'invalid format' text #2296. Recommend skipping it._read_sint/_make_sint. MH is the only user. Recommend skipping them and keeping MH's own code.JarryShaw commentedon Nov 2, 2026
JarryShaw commentedon Nov 2, 2026
The owner's answers, paraphrased:
pad_lengthgoes incorekit.fields.strings._make_uintraises on out-of-range values instead of wrapping them. Signed and sentinel PCAP-NG fields keep masking and get a per-field review._make_octetsis taken if it has call sites and skipped if not. The audit found it replacing about a dozen fix(protocols): makers reject bad arguments with the reader's 'invalid format' text #2296 messages, so it is taken, and those messages are re-pinned._read_sint/_make_sintmove to the base class, even though MH is their only user.Every question is answered. The padding helper (
pad_length, withPaddingField(align=…)adopted across the PCAP-NG, SCTP and HIP schemas) does not depend on #2595, so a worker is on it now. The other commit groups use #2595's helpers and are dispatched once it merges.refactor(corekit): add pad_length and PaddingField(align=, after=) (#…
refactor(protocols): finish the shared value helpers and move TLS ont…
4 remaining items
JarryShaw commentedon Nov 2, 2026
take 2
JarryShaw commentedon Nov 2, 2026
The owner chose 2, paraphrased.
section_lengthkeeps-1as its "not specified" sentinel and accepts the range from-2**63to2**64 - 1, with-1and0xFFFFFFFFFFFFFFFFreading back alike. Anything outside that range, and anybool, raisesProtocolError, per #2617. Masking survives only where it maps the signed spelling onto the unsigned one.This settles the question, so
needs: decisioncomes off. It goes into the PCAP-NG group's commit, with a test for each refused case and for each edge of the range. Thedrop_countdecision recorded above stands.JarryShaw commentedon Nov 2, 2026
The transport group is #2670 and the PCAP-NG/ARP group is #2671. The internet group follows.
refactor(protocols)!: range-check the transport makers and adopt the …
refactor(protocols)!: finish the PCAP-NG and ARP value helpers (#2614) (
JarryShaw commentedon Nov 2, 2026
The PR is #2677. It is the last group; #2669 and #2674 unblock when it merges.
refactor(protocols)!: range-check the IPv6 extension, MH, HIP and IPv…
refactor(protocols)!: group each protocol into one package (#2534)
refactor(protocols)!: group each protocol into one package (#2534)
refactor(protocols)!: group each protocol into one package (#2534)
refactor(protocols)!: group each protocol's protocol, schema and data…