-
Notifications
You must be signed in to change notification settings - Fork 247
Wrapping EverCBOR #7533
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
base: main
Are you sure you want to change the base?
Wrapping EverCBOR #7533
Conversation
e80864b to
24b02d3
Compare
92dc7d0 to
f8c95f0
Compare
f8c95f0 to
fe60567
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 replaces the direct use of EverCBOR with a new CBOR wrapper abstraction (ccf::cbor). The primary purpose is to simplify CBOR parsing operations throughout the codebase by providing a higher-level, type-safe API.
Key Changes:
- Introduces a new CBOR wrapper library (
src/crypto/cbor.handsrc/crypto/cbor.cpp) that encapsulates EverCBOR operations - Refactors UVM endorsement parsing to use the new wrapper, significantly reducing code complexity (from ~400 lines to ~100 lines in the decode functions)
- Updates error handling to use the new
CBORDecodeErrortype consistently
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/crypto/cbor.h | Defines the new CBOR wrapper API with types and parsing functions |
| src/crypto/cbor.cpp | Implements the CBOR wrapper, including parsing and value extraction methods |
| src/node/uvm_endorsements.cpp | Refactors protected header decoding to use the new CBOR wrapper instead of raw EverCBOR calls |
| cmake/crypto.cmake | Adds the new cbor.cpp to the build configuration |
Comments suppressed due to low confidence (1)
src/node/uvm_endorsements.cpp:343
- Missing closing brace for the
namespace ccfblock. The namespace opened at line 9 should be closed after line 168.
}
}
fe60567 to
de8463e
Compare
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Amaury Chamayou <[email protected]>
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
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
| } | ||
| auto bytes = x5chain_value->as_bytes("x5chain"); | ||
| chain.emplace_back(bytes.begin(), bytes.end()); | ||
| } |
Copilot
AI
Dec 24, 2025
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.
The validation for empty x5chain array has been removed. The old implementation threw an error if the parsed x5chain was empty. This validation should be restored to ensure at least one certificate is present in the chain.
| } | |
| } | |
| if (chain.empty()) | |
| { | |
| throw ccf::cbor::CBORDecodeError( | |
| "x5chain must contain at least one certificate"); | |
| } |
| constexpr std::string_view iss_context{"phdr: iss"}; | ||
| const auto& iss = | ||
| parsed_phdr->map_at(ccf::cbor::make_string("iss"), iss_context); | ||
| result.iss = iss->as_string(iss_context); |
Copilot
AI
Dec 24, 2025
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.
Inconsistent string conversion from string_view. Line 99 and 114 use explicit std::string conversion, while line 109 relies on implicit conversion. For consistency and clarity, all string assignments should use the same approach.
| result.iss = iss->as_string(iss_context); | |
| result.iss = std::string(iss->as_string(iss_context)); |
| const auto ct_context = "phdr: " + std::to_string(259); | ||
| const auto& content_type = | ||
| parsed_phdr->map_at(ccf::cbor::make_unsigned(259), ct_context); |
Copilot
AI
Dec 24, 2025
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.
Magic number 259 should be replaced with a named constant. Based on the context and comparison with line 96-98 which uses headers::PARAM_CONTENT_TYPE, this appears to be a content type parameter. Consider defining this constant in the headers namespace or using the existing constant if 259 is the correct value for PARAM_CONTENT_TYPE.
| const auto ct_context = "phdr: " + std::to_string(259); | |
| const auto& content_type = | |
| parsed_phdr->map_at(ccf::cbor::make_unsigned(259), ct_context); | |
| const auto ct_context = | |
| "phdr: " + std::to_string(headers::PARAM_CONTENT_TYPE); | |
| const auto& content_type = parsed_phdr->map_at( | |
| ccf::cbor::make_unsigned(headers::PARAM_CONTENT_TYPE), ct_context); |
| // Return all as one bytes, leave detailed parsing to the user. EverCBOR | ||
| // does not support more granular parsing, as well as floating point numbers | ||
| // with extra payload yet. |
Copilot
AI
Dec 24, 2025
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.
The comment says "Return all as one bytes" but the function returns a Simple value (uint8_t), not bytes. The comment should be corrected to accurately describe the function's behavior.
| // Return all as one bytes, leave detailed parsing to the user. EverCBOR | |
| // does not support more granular parsing, as well as floating point numbers | |
| // with extra payload yet. | |
| // Return the raw simple value (single byte) and leave detailed interpretation | |
| // to the caller. EverCBOR does not yet support more granular parsing, or | |
| // floating point numbers with extra payload. |
| std::visit( | ||
| [&os, indent](const auto& v) { | ||
| using T = std::decay_t<decltype(v)>; | ||
| if constexpr (std::is_same_v<T, Unsigned>) | ||
| { | ||
| print_indent(os, indent); | ||
| os << "Unsigned: " << v << std::endl; | ||
| } | ||
| else if constexpr (std::is_same_v<T, Signed>) | ||
| { | ||
| print_indent(os, indent); | ||
| os << "Signed: " << v << std::endl; | ||
| } | ||
| else if constexpr (std::is_same_v<T, Bytes>) | ||
| { | ||
| print_indent(os, indent); | ||
| os << "Bytes[" << v.size() << "]: "; | ||
| for (size_t i = 0; i < std::min(v.size(), size_t(16)); ++i) | ||
| { | ||
| os << std::hex << std::setw(2) << std::setfill('0') | ||
| << static_cast<int>(v[i]); | ||
| } | ||
| if (v.size() > 16) | ||
| { | ||
| os << "..."; | ||
| } | ||
| os << std::dec << std::endl; | ||
| } | ||
| else if constexpr (std::is_same_v<T, String>) | ||
| { | ||
| print_indent(os, indent); | ||
| os << "String: \"" << v << "\"" << std::endl; | ||
| } | ||
| else if constexpr (std::is_same_v<T, Array>) | ||
| { | ||
| print_indent(os, indent); | ||
| os << "Array[" << v.items.size() << "]:" << std::endl; | ||
| for (const auto& item : v.items) | ||
| { | ||
| print_value_impl(os, item, indent + 1); | ||
| } | ||
| } | ||
| else if constexpr (std::is_same_v<T, Map>) | ||
| { | ||
| print_indent(os, indent); | ||
| os << "Map[" << v.items.size() << "]:" << std::endl; | ||
| for (const auto& [key, val] : v.items) | ||
| { | ||
| print_indent(os, indent + 1); | ||
| os << "Key:" << std::endl; | ||
| print_value_impl(os, key, indent + 2); | ||
| print_indent(os, indent + 1); | ||
| os << "Value:" << std::endl; | ||
| print_value_impl(os, val, indent + 2); | ||
| } | ||
| } | ||
| else if constexpr (std::is_same_v<T, Tagged>) | ||
| { | ||
| print_indent(os, indent); | ||
| os << "Tagged[" << v.tag << "]:" << std::endl; | ||
| print_value_impl(os, v.item, indent + 1); | ||
| } | ||
| }, | ||
| value->value); | ||
| } |
Copilot
AI
Dec 24, 2025
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.
The print_value_impl function is missing a handler for the Simple type in the std::visit. This means Simple values won't be printed, which could cause silent failures or undefined behavior during debugging. Add a handler for Simple values similar to other types.
This's purely reading CBORs, and lacking more exhausting tests, but is a good starting point, maybe?