Add generic codec base class combining shared ASN.1/CBOR codec logic#29
Draft
Copilot wants to merge 2 commits into
Draft
Add generic codec base class combining shared ASN.1/CBOR codec logic#29Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Co-authored-by: polybassa <1676055+polybassa@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add generic codec class for ASN1 and CBOR
Add generic codec base class combining shared ASN.1/CBOR codec logic
Mar 17, 2026
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.
BERcodec_ObjectandCBORcodec_Objectduplicated the same metaclass registration pattern,check_string,dec(safe-mode skeleton), andsafedec. This extracts those identical parts into a shared base inscapy/libs/codec.py.New:
scapy/libs/codec.pyGenericCodec_metaclass— handlesc.tag.register(c.codec, c)once; exposes_handle_registration_errorhook for format-specific loggingGenericCodecObject[_K]— provides the shared methods:check_string— parameterised by_decoding_error_classdec— parameterised by_generic_error_classes+_decoding_error_object_class; covers CBOR fully, overridable for BER'sBadTagrecoverysafedec— was 100% identical in both; now lives in one placeenc— abstract stubscapy/asn1/ber.pyBERcodec_metaclass→ inheritsGenericCodec_metaclass; overrides_handle_registration_errorwithwarning()BERcodec_Object→ inheritsGenericCodecObject; removescheck_string+safedec; retainsdecoverride forBER_BadTag_Decoding_Errorrecovery pathscapy/cbor/cborcodec.pyCBORcodec_metaclass→ inheritsGenericCodec_metaclass; overrides_handle_registration_errorwithlog_runtime.error()CBORcodec_Object→ inheritsGenericCodecObject; removescheck_string,dec, andsafedecentirely — all three are now fully inheritedUsage pattern for new codec formats
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.