scapy icon indicating copy to clipboard operation
scapy copied to clipboard

Add CBOR codec and BPv7 packet classes

Open BrianSipos opened this issue 1 month ago • 5 comments

This change addresses #4874 by adding new base scapy classes to encode and decode CBOR structure RFC 8949. This is in support of a new protocol support for BPv7 RFC 9171. This work was adapted from earlier out-of-source additions from dtn-demo-agent.

Both include a minimal set of unit tests to cover normal behavior. Since this is focused on immediate needs for BPv7 the CBOR fields and packets are not exhaustive.

Fixes #4874

BrianSipos avatar Nov 18 '25 02:11 BrianSipos

@BrianSipos Thanks a lot for this PR.

Please have a look at the failing tests.

I would also recommend to move the CBOR implementation into "contrib".

polybassa avatar Nov 26 '25 08:11 polybassa

Codecov Report

:x: Patch coverage is 18.70702% with 591 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 48.00%. Comparing base (3255441) to head (a5b8d37). :warning: Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
scapy/contrib/bpv7.py 0.44% 225 Missing :warning:
scapy/cbor.py 23.52% 208 Missing :warning:
scapy/cborfields.py 30.90% 114 Missing :warning:
scapy/cborpacket.py 27.86% 44 Missing :warning:

:exclamation: There is a different number of reports uploaded between BASE (3255441) and HEAD (a5b8d37). Click for more details.

HEAD has 10 uploads less than BASE
Flag BASE (3255441) HEAD (a5b8d37)
12 2
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #4875       +/-   ##
===========================================
- Coverage   80.87%   48.00%   -32.88%     
===========================================
  Files         368      354       -14     
  Lines       90262    90663      +401     
===========================================
- Hits        72998    43521    -29477     
- Misses      17264    47142    +29878     
Files with missing lines Coverage Δ
scapy/all.py 100.00% <100.00%> (ø)
scapy/cborpacket.py 27.86% <27.86%> (ø)
scapy/cborfields.py 30.90% <30.90%> (ø)
scapy/cbor.py 23.52% <23.52%> (ø)
scapy/contrib/bpv7.py 0.44% <0.44%> (ø)

... and 320 files with indirect coverage changes

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

codecov[bot] avatar Nov 26 '25 08:11 codecov[bot]

@polybassa one need for BPv7 is a CRC-16 and CRC-32C generator. Right now this uses crcmod package, which has not been updated in a while but is still recent Python compatible. Do you have any preference about how to generate CRC values? I don't see other packages used from other protocols in scapy.

BrianSipos avatar Nov 26 '25 14:11 BrianSipos

@gpotter2 What do you think about using #4855 for this?

polybassa avatar Nov 27 '25 20:11 polybassa

@BrianSipos We will merge #4855 into Scapy. However, we didn't decided yet into which directory. Can you use the crc implementation from this PR for your use case?

polybassa avatar Dec 02 '25 09:12 polybassa

@BrianSipos We will merge #4855 into Scapy. However, we didn't decided yet into which directory. Can you use the crc implementation from this PR for your use case?

I believe so. The ones depended upon originally are well documented to be able to check known inputs.

Any idea if the CBOR portions of this PR are any more likely to be accepted than the other PR? When submitting this one, I didn't even realize there was an alternative one. The CBOR portion of this PR is, I believe, more general purpose and does not need any outside/new library dependencies for scapy.

BrianSipos avatar Dec 12 '25 03:12 BrianSipos

Hi. Yeah we need to take the time to compare them both and get the best one (or take the good ideas and tests from both).

Sorry for the delay. (I should have much more time available around the holidays to review all of that..)

gpotter2 avatar Dec 12 '25 08:12 gpotter2