Skip to content

asn1: prepare fields for pluggable codecs#5049

Open
polybassa wants to merge 3 commits into
secdev:masterfrom
polybassa:asn1-generic-codec-hooks
Open

asn1: prepare fields for pluggable codecs#5049
polybassa wants to merge 3 commits into
secdev:masterfrom
polybassa:asn1-generic-codec-hooks

Conversation

@polybassa

Copy link
Copy Markdown
Contributor

Dispatch tagging via codec stems and pass codec kwargs through ASN1F encode/decode so additional codecs can register without hardcoding BER in every field path.

AI-Assisted: yes (Cursor)

Dispatch tagging via codec stems and pass codec kwargs through
ASN1F encode/decode so additional codecs can register without
hardcoding BER in every field path.

AI-Assisted: yes (Cursor)
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.59701% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.29%. Comparing base (73435c1) to head (24a4971).

Files with missing lines Patch % Lines
scapy/asn1fields.py 79.52% 26 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5049      +/-   ##
==========================================
+ Coverage   80.22%   80.29%   +0.06%     
==========================================
  Files         388      388              
  Lines       96467    96535      +68     
==========================================
+ Hits        77394    77509     +115     
+ Misses      19073    19026      -47     
Files with missing lines Coverage Δ
scapy/asn1/ber.py 96.13% <100.00%> (+13.41%) ⬆️
scapy/asn1fields.py 84.75% <79.52%> (+1.11%) ⬆️

... and 7 files with indirect coverage changes

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

AI-Assisted: yes (Cursor)

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 refactors ASN.1 field encode/decode paths to be codec-stem driven (rather than BER-hardcoded), enabling additional ASN.1 codecs to plug in tagging behavior and receive codec kwargs consistently across field operations.

Changes:

  • Added codec-stem dispatch for tagging encode/decode and threaded codec kwargs through ASN1F field encode/decode paths.
  • Updated BER implementation to respect conf.ASN1_default_long_size for explicit-tag length encoding and to tolerate extra kwargs in decode APIs.
  • Added BER-focused regression/coverage tests for packets/fields and codec helpers, wired into asn1.uts.

Reviewed changes

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

Show a summary per file
File Description
test/scapy/layers/ber_packets.py Adds BER ASN1_Packet / ASN1F field roundtrip tests (explicit tags, fixed sizes, optional, choice, sequence-of).
test/scapy/layers/ber_codec.py Adds targeted tests for BER helper functions, codecs, and error formatting.
test/scapy/layers/asn1.uts Integrates the new BER packet/codec tests into the existing ASN.1 UTS suite.
scapy/asn1fields.py Implements codec-stem tagging dispatch, passes codec kwargs through field encode/decode, and refactors SEQUENCE/CHOICE/SEQUENCE_OF internals.
scapy/asn1/ber.py Makes BER explicit-tag length encoding respect conf.ASN1_default_long_size and updates codec APIs to accept passthrough kwargs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scapy/asn1fields.py Outdated
AI-Assisted: yes (Cursor)

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread scapy/asn1fields.py
Comment on lines +664 to +667
elif self.holds_packets:
s = b"".join(bytes(i) for i in val)
else:
s = b"".join(self.fld._encode_item(pkt, i) for i in val)
Comment thread scapy/asn1fields.py
Comment on lines +222 to +224
s = self.ASN1_tag.get_codec(pkt.ASN1_codec).enc(
x, **self._codec_kwargs()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants