-
Notifications
You must be signed in to change notification settings - Fork 247
Better CBOR wrappers #7549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better CBOR wrappers #7549
Conversation
ec187c0 to
771af29
Compare
f3ab01c to
e9a6c40
Compare
e9a6c40 to
3359b9a
Compare
There was a problem hiding this comment.
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 the CBOR wrapper API to simplify error handling and improve usability. The changes remove context parameters from accessor methods in favor of a new rethrow_with_context helper function, allow signed/unsigned integer key equivalence in maps, rename functions for clarity (e.g., parse_value → parse, print_value → to_string), and add comprehensive test coverage.
Key Changes
- Error handling simplified with
rethrow_with_contexthelper that allows flexible context stacking without duplicating messages - Integer key comparison now treats
signed(42)andunsigned(42)as equal in map lookups - API functions renamed for clarity and consistency (
parse,to_stringinstead ofparse_value,print_value) - Added
SimpleValueenum for common CBOR simple values (False, True, Null) - Added extensive test suite with 70+ test cases covering various CBOR data types
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/crypto/cbor.h | Adds SimpleValue enum, removes context parameters from method signatures, adds rethrow_with_context helper, renames parse_value/print_value to parse/to_string, adds make_bytes helper |
| src/crypto/cbor.cpp | Removes with_context helper, implements signed_equals_unsigned for map key comparison, adds signed/unsigned cross-conversion in as_signed/as_unsigned, updates to_string to remove trailing newline, improves bytes/simple value printing |
| src/node/uvm_endorsements.cpp | Updates to use new CBOR API with rethrow_with_context pattern, removes context parameters from accessor calls, changes to use parse instead of parse_value, uses new PARAM_CONTENT_TYPE_HASH_ENVELOPE constant |
| src/node/cose_common.h | Adds PARAM_CONTENT_TYPE_HASH_ENVELOPE constant (value 259) for COSE hash envelope content type |
| src/crypto/test/cbor.cpp | New comprehensive test file with 70+ test cases covering integers, strings, bytes, simple values, tags, arrays, maps, and error conditions |
| CMakeLists.txt | Adds cbor_test unit test target |
Co-authored-by: Copilot <[email protected]>
One more step towards #7542
❗ More of an incremental improvement rather than a finalised version, therefore no fancy docstrings/documentation, etc. It will come once we throw QCBOR away and are fully settled on these wrappers' interface.
Changelist
signed(42)andunsigned(42)now\nat the end whento_string()ingSimpleValueenum type for commonly used types✅ Long Test