Improve RFC 3779 extension api - #4890
Conversation
|
I'm not sure why we didn't do it this way in the first place, sorry about that. I think doing it this way is way nicer for the user, because they don't need to understand the semantic of a random |
|
@randombit I'm currently redoing all the tests, and I can test the encode by comparing the expected bits to |
|
The API I'm mostly happy with now, though I'm still debating whether there should be helper methods for things like "inherited", or if the user should interpret the |
|
@arckoor Thanks I'll take a look asap. Can you please start by rebasing against latest master? There has been recently introduced some new checks in CI (most notably clang-tidy runs against headers now, while previously it only ran on |
71ee618 to
0636720
Compare
|
🤔 |
0636720 to
c0f2827
Compare
c0f2827 to
71b9294
Compare
|
@randombit can I please get a review of this? The next release is drawing closer, and we need to either merge this or revert #4699. We cannot leave it as is. |
|
@arckoor Thanks for the ping I'll review soon |
randombit
left a comment
There was a problem hiding this comment.
@arckoor So the changes to x509_ext.{h,cpp} seem basically fine but tbh this PR is very hard to review because it both changes the API and modifies the tests both in terms of API usage but also what is being tested. The diff is basically unreadable.
I can see how for heavy usage the new API might be preferable; you are obviously more invested in this being ergonomic than I am. That said I generally prefer avoiding mutable interfaces (eg how restrict_rdi deletes previously entered state) especially since with X.509 extensions the only time the data is really (logically) mutable is during creation rather than after.
So I'd propose this
- You removed or made private various constructors (eg
ASBlocks) that had a fairly verbose but IMO usable interface. Bring these back. - Don't remove any of the existing tests (using the old, currently removed, interfaces).
- Add new tests using your new interface
That admittedly leaves us with two slightly different ways of accomplishing creating an ASBlocks but TBH given the choice between the two I would prefer the verbose way of creating ASIdentifier list. And it should make then the diff comprehensible/reviewable.
|
@randombit fair points, I'll add the old constructors back in, but I'd really like to keep even the mutable methods like |
Yes that's fine.
That would work but perhaps that's not necessary in practice. In decoding , |
71b9294 to
04040a6
Compare
|
@randombit should be ready to take a look again. The only changed test I kept as it was is the decode test, since I find straight values more easily readable than hex. It also tests something different, since the logic was just wrong there.
|
randombit
left a comment
There was a problem hiding this comment.
This looks good to me. Can you clean up the commit history? Just squash to 1 if you like or try to split into API improvements vs new tests, however you prefer.
|
There is also a merge conflict |
b95e6bb to
7b85809
Compare
7b85809 to
691bc67
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors and enhances the RFC 3779 extension API by adding builder-style methods, improving parsing/merging logic, and updating tests to use the new API.
- Add helper overload in tests.h for comparing
std::array<uint8_t, N>buffers. - Introduce
add_address,restrict, andinheritmethods forIPAddressBlocksand analogous methods forASBlocks. - Update decoding routines to automatically sort and merge entries, and refresh all tests to use the new API patterns.
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/tests/tests.h | Added test_eq overload for std::array<uint8_t, N> |
| src/tests/test_x509_rpki.cpp | Added builder-style tests and refactored existing ones |
| src/lib/x509/x509_ext.h | Exposed builder methods and made constructors explicit |
| src/lib/x509/x509_ext.cpp | Invoke sort_and_merge after decoding and updated encode/decode routines |
| src/tests/data/x509/x509test/*.pem | Added new test certificates |
Comments suppressed due to low confidence (3)
src/tests/test_x509_rpki.cpp:278
- [nitpick] The message says "block 24" but this is checking index 4. Update the description to "block 4 has correct safi" for clarity.
result.test_eq("block 24 has correct safi", addr_blocks[4].safi(), std::optional<uint8_t>{1});
src/tests/test_x509_rpki.cpp:1500
- [nitpick] This test is for ASBlocks, but the description says "IP Address Blocks". Change it to "X509 AS Blocks encode (builder)".
Test::Result result("X509 IP Address Blocks encode (builder)");
src/lib/x509/x509_ext.h:738
- [nitpick] The method name
restrictmay be confused with a C/C++ keyword. Consider renaming torestrict_addressesor similar for clearer intent.
void restrict(std::optional<uint8_t> safi = std::nullopt) {
| void add_asnum(asnum_t asnum) { add_asnum(asnum, asnum); } | ||
|
|
||
| /// Add an asnum range to this extension | ||
| void add_asnum(asnum_t min, asnum_t max) { |
There was a problem hiding this comment.
[nitpick] The builder does not merge or sort overlapping AS ranges after adding. Consider invoking a merge step (e.g., sort_and_merge_ranges) to maintain a normalized, sorted list.
#4699 added x509 extensions for RFC 3779. While working on #4877 I realized that the api for actually using them is kind of horrible.