Skip to content

asn1: prepare fields for pluggable codecs#5049

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

asn1: prepare fields for pluggable codecs#5049
polybassa wants to merge 6 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 39.25926% with 82 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.48%. Comparing base (73435c1) to head (c5b7a57).

Files with missing lines Patch % Lines
scapy/asn1fields.py 36.71% 81 Missing ⚠️
scapy/asn1/ber.py 85.71% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (73435c1) and HEAD (c5b7a57). Click for more details.

HEAD has 10 uploads less than BASE
Flag BASE (73435c1) HEAD (c5b7a57)
12 2
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #5049       +/-   ##
===========================================
- Coverage   80.22%   47.48%   -32.74%     
===========================================
  Files         388      370       -18     
  Lines       96467    96166      -301     
===========================================
- Hits        77394    45668    -31726     
- Misses      19073    50498    +31425     
Files with missing lines Coverage Δ
scapy/asn1/ber.py 45.73% <85.71%> (-36.99%) ⬇️
scapy/asn1fields.py 55.69% <36.71%> (-27.95%) ⬇️

... and 338 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 Outdated
Comment thread scapy/asn1fields.py Outdated
Comment thread scapy/asn1fields.py
Comment thread scapy/asn1fields.py Outdated
Nils Weiss added 3 commits July 21, 2026 15:10
AI-Assisted: yes (Cursor)
  Apply field tagging in SEQUENCE OF builds, honor size_len for
  ASN1_Object values, and trim redundant optional/tagging helpers.

AI-Assisted: yes (Cursor)
… values (e.g. KRB_AuthenticatorChecksum in an ASN1F_STRING) used

  self_build() alone and skipped the BER OCTET STRING wrap (04 …). Optional cksum then failed to decode, so the stream still had 0xa3
  when cusec (0xa4) was expected.

AI-Assisted: yes (Cursor)
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.

3 participants