asn1: prepare fields for pluggable codecs#5049
Open
polybassa wants to merge 3 commits into
Open
Conversation
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 Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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_sizefor 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.
AI-Assisted: yes (Cursor)
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 on lines
+222
to
+224
| s = self.ASN1_tag.get_codec(pkt.ASN1_codec).enc( | ||
| x, **self._codec_kwargs() | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)