Skip to content

Remove orb() - #5062

Merged
polybassa merged 2 commits into
secdev:masterfrom
gpotter2:orb-removal
Aug 14, 2026
Merged

Remove orb()#5062
polybassa merged 2 commits into
secdev:masterfrom
gpotter2:orb-removal

Conversation

@gpotter2

Copy link
Copy Markdown
Member
  • remove orb, which was used for the Python 2 / Python 3 compatibility, but is no longer necessary.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.90123% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.58%. Comparing base (3f7bed3) to head (9dcc85d).

Files with missing lines Patch % Lines
scapy/contrib/http2.py 89.58% 5 Missing ⚠️
scapy/modules/krack/crypto.py 0.00% 5 Missing ⚠️
scapy/contrib/isotp/isotp_scanner.py 66.66% 2 Missing ⚠️
scapy/contrib/openflow.py 66.66% 2 Missing ⚠️
scapy/contrib/openflow3.py 75.00% 2 Missing ⚠️
scapy/arch/__init__.py 0.00% 1 Missing ⚠️
scapy/contrib/automotive/gm/gmlan_scanner.py 0.00% 1 Missing ⚠️
scapy/contrib/automotive/uds_scan.py 0.00% 1 Missing ⚠️
scapy/contrib/bgp.py 94.44% 1 Missing ⚠️
scapy/contrib/cdp.py 75.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5062      +/-   ##
==========================================
- Coverage   80.59%   80.58%   -0.02%     
==========================================
  Files         390      390              
  Lines       96841    96798      -43     
==========================================
- Hits        78048    78003      -45     
- Misses      18793    18795       +2     
Files with missing lines Coverage Δ
scapy/asn1/asn1.py 86.84% <100.00%> (ø)
scapy/asn1/ber.py 96.18% <100.00%> (ø)
scapy/cbor/cborcodec.py 87.77% <100.00%> (ø)
scapy/compat.py 90.76% <ø> (-0.54%) ⬇️
scapy/contrib/automotive/ecu.py 93.24% <100.00%> (-0.35%) ⬇️
scapy/contrib/automotive/gm/gmlan.py 99.18% <100.00%> (-0.01%) ⬇️
scapy/contrib/automotive/kwp.py 95.68% <100.00%> (-0.02%) ⬇️
scapy/contrib/automotive/obd/obd.py 97.50% <100.00%> (-0.04%) ⬇️
scapy/contrib/automotive/scanner/enumerator.py 92.42% <100.00%> (-0.02%) ⬇️
scapy/contrib/automotive/someip.py 95.17% <100.00%> (ø)
... and 70 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gpotter2
gpotter2 force-pushed the orb-removal branch 8 times, most recently from d6ce20c to 58652a8 Compare July 29, 2026 23:28
@gpotter2 gpotter2 added the cleanup Performs some code clean-up label Jul 29, 2026
AI-Assisted: yes (GPT-5.3-Codex)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the legacy orb() compatibility helper (previously used for Python 2/3 byte handling) and updates Scapy code/tests to use native Python 3 bytes/int semantics instead.

Changes:

  • Removed orb() from scapy/compat.py and eliminated related imports/usages across core layers and contrib modules.
  • Updated numerous protocol parsers/builders to use direct byte indexing (b[0], iteration yielding ints) and adjusted a few string/bytes expectations in tests.
  • Refactored parts of the HTTP/2 HPACK implementation to operate more consistently on bytes (but a few regressions were introduced; see comments).

Reviewed changes

Copilot reviewed 86 out of 86 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/scapy/layers/tls/tls.uts Remove orb() use in TLS test assertion.
test/scapy/layers/inet6.uts Remove orb() use in IPv6 tests; adjust byte handling.
test/regression.uts Drop orb references; update tests to pass bytes where required.
test/contrib/tcpao.uts Remove orb() when parsing first byte for IP version.
test/contrib/mqttsn.uts Use bytes literals instead of text strings for packet inputs.
test/contrib/http2.uts Update expectations to match new HPACK decode return type.
scapy/utils6.py Replace orb() byte conversions with direct indexing/iteration.
scapy/utils.py Remove orb() use in byte formatting and sanitization utilities.
scapy/sessions.py Replace XOR byte handling with direct int XOR from bytes iteration.
scapy/packet.py Remove orb() use in canvas dump hex formatting.
scapy/modules/p0f.py Replace TCP option parsing orb() calls with direct indexing.
scapy/modules/krack/crypto.py Remove orb() in TKIP parsing/building paths.
scapy/libs/rfc3961.py Replace orb() in DES parity/XOR helpers with direct byte ints.
scapy/layers/zigbee.py Remove orb() from dispatch hook byte reads.
scapy/layers/x509.py Switch ASN.1 BIT STRING defaults from "" to b"" where appropriate.
scapy/layers/vrrp.py Replace orb() byte reads in dispatch hooks.
scapy/layers/tls/tools.py Replace orb() for padding length extraction.
scapy/layers/tls/record.py Replace orb() for message type/padlen extraction.
scapy/layers/tls/record_tls13.py Replace orb() for record type extraction.
scapy/layers/tls/record_sslv2.py Replace orb() for message type/padlen extraction.
scapy/layers/tls/keyexchange.py Replace orb() when guessing curve type.
scapy/layers/tls/handshake.py Replace orb() in handshake length packing.
scapy/layers/tls/basefields.py Replace orb() in padding-length extraction.
scapy/layers/sixlowpan.py Replace orb() in link-local address bit manipulation.
scapy/layers/sctp.py Replace orb() in checksum/adler and payload guessing logic.
scapy/layers/pptp.py Replace orb() in dispatch hook option selection.
scapy/layers/ppp.py Replace orb() in multiple PPP dispatch hooks.
scapy/layers/ntp.py Replace orb() for first-byte dispatch inspection.
scapy/layers/lltd.py Replace orb() for flags/cmd extraction.
scapy/layers/llmnr.py Replace orb() for response bit check.
scapy/layers/ipsec.py Replace orb() for ESP padlen/next-header extraction.
scapy/layers/inet6.py Replace orb() across multiple IPv6 parsing helpers.
scapy/layers/inet.py Replace orb() in IP/TCP option parsing and header manipulation.
scapy/layers/eap.py Replace orb() in EAP dispatch hook parsing.
scapy/layers/dot15d4.py Replace orb() in FCS computation.
scapy/layers/dot11.py Replace orb() in multiple 802.11 parsing/dispatch paths.
scapy/layers/dhcp6.py Replace orb() in DHCPv6 type dispatch.
scapy/layers/dhcp.py Replace orb() and ensure values passed to sane() are bytes.
scapy/layers/clns.py Replace orb() in NLPID extraction.
scapy/layers/bluetooth4LE.py Replace orb() in BLE bit swapping loop.
scapy/contrib/tzsp.py Replace orb() for tag parsing and lengths.
scapy/contrib/tcpao.py Replace orb() in TCP option parsing loop.
scapy/contrib/tacacs.py Replace orb() with direct XOR of indexed ints.
scapy/contrib/scada/pcom.py Replace orb() in checksum computation.
scapy/contrib/scada/iec104/iec104_fields.py Replace orb() in sequence number parsing.
scapy/contrib/scada/iec104/init.py Replace orb() in APCI/APDU parsing and checks.
scapy/contrib/rtr.py Replace orb() for version/type extraction.
scapy/contrib/rpl_metrics.py Replace orb() for option type extraction.
scapy/contrib/pnio_dcp.py Replace orb() for option/suboption extraction.
scapy/contrib/pim.py Replace orb() for TLV type extraction.
scapy/contrib/pfcp.py Replace orb() in APN parsing and IE type extraction.
scapy/contrib/ospf.py Replace orb() for LSA type extraction.
scapy/contrib/openflow3.py Replace orb() for OXM/header byte extraction.
scapy/contrib/openflow.py Replace orb() for version/type byte extraction.
scapy/contrib/mysql.py Replace orb() for header/command byte parsing.
scapy/contrib/mqttsn.py Replace orb() in variable-length parsing.
scapy/contrib/mqtt.py Replace orb() in remaining-length decoding loop.
scapy/contrib/modbus.py Replace orb() for function/sub-code extraction.
scapy/contrib/mac_control.py Replace orb() in opcode extraction.
scapy/contrib/lldp.py Replace orb() in TLV matching and TLV type parsing.
scapy/contrib/ldp.py Replace orb() in mask/flags extraction.
scapy/contrib/isotp/isotp_scanner.py Replace orb() in PCI/FC extraction and formatting.
scapy/contrib/isotp/isotp_packet.py Replace orb() in PCI nibble parsing.
scapy/contrib/isis.py Replace orb() in ID formatting and TLV type extraction.
scapy/contrib/http2.py Remove orb() and refactor HPACK string handling and frame byte sizing.
scapy/contrib/gtp.py Replace orb() in dispatch and field parsing.
scapy/contrib/gtp_v2.py Replace orb() in IE/PCO dispatch parsing.
scapy/contrib/esmc.py Replace orb() in payload dispatch.
scapy/contrib/eddystone.py Replace orb() in URL encode/decode loops.
scapy/contrib/diameter.py Replace orb() usage with bytes-aware iteration.
scapy/contrib/cdp.py Replace orb() in length parsing and checksum padding logic.
scapy/contrib/bgp.py Replace orb() in extensive BGP parsing/dispatch code.
scapy/contrib/automotive/uds.py Replace orb() in single-layer service dispatch.
scapy/contrib/automotive/uds_scan.py Replace orb() when building IntelHex output.
scapy/contrib/automotive/someip.py Replace orb() in SD entry/option dispatch parsing.
scapy/contrib/automotive/scanner/enumerator.py Replace orb() in response classification logic.
scapy/contrib/automotive/obd/obd.py Replace orb() in single-layer service dispatch.
scapy/contrib/automotive/kwp.py Replace orb() in single-layer service dispatch.
scapy/contrib/automotive/gm/gmlan.py Replace orb() in single-layer service dispatch.
scapy/contrib/automotive/gm/gmlan_scanner.py Replace orb() when building IntelHex output.
scapy/contrib/automotive/ecu.py Replace orb() in response sorting key.
scapy/compat.py Remove orb() from public API and exports.
scapy/cbor/cborcodec.py Replace orb() in CBOR head decoding.
scapy/asn1/ber.py Replace orb() in BER length/id/num decoding.
scapy/asn1/asn1.py Update BIT STRING readable handling to be bytes-centric.
scapy/arch/init.py Replace orb() in MAC formatting helper.
Suppressed comments (2)

scapy/contrib/http2.py:1108

  • huffman_decode() currently decodes the reconstructed byte string with the default UTF-8 codec. HPACK string literals are defined as opaque octet sequences, so decoding can raise UnicodeDecodeError for valid header values and prevents round-tripping non-UTF8 bytes. Use plain_str() (backslashreplace) for a safe textual representation instead.
        s = b''.join(s)
        return s.decode()

scapy/contrib/http2.py:1301

  • HPackStrLenField.any2i() no longer accepts plain Python str values: it only handles bytes (parsed form) or HPackStringsInterface instances, so constructing HTTP/2/HPACK packets with normal string field values will assert/fail. Handle str by delegating to h2i() (i.e., wrap in HPackLiteralString).
        if isinstance(x, bytes):
            assert isinstance(pkt, packet.Packet)
            return self.m2i(pkt, x)
        assert isinstance(x, HPackStringsInterface)
        return x

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scapy/contrib/http2.py
@polybassa

Copy link
Copy Markdown
Contributor

I Hope you could do most of that changes with a regex

@polybassa
polybassa merged commit b36473a into secdev:master Aug 14, 2026
23 checks passed
@gpotter2
gpotter2 deleted the orb-removal branch August 14, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Performs some code clean-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants