Skip to content

Add support for SET#600

Merged
alex merged 2 commits intoalex:mainfrom
trail-of-forks:ft/set-impl
Feb 25, 2026
Merged

Add support for SET#600
alex merged 2 commits intoalex:mainfrom
trail-of-forks:ft/set-impl

Conversation

@facutuesca
Copy link
Contributor

asn1::Set has a similar API to asn1::Sequence for encoding and decoding, except the order of the elements is checked

// decoding
parser.read_element::<Set<'_>>()?.parse(|p| { 
// ...parse each element
}


// encoding
writer.write_element(&SetWriter::new(&|w: &mut SetElementWriter<'_>| {
    w.write_element(&a)?
    w.write_element(&b)?
    //...etc
}))

Fixes #530

@facutuesca facutuesca force-pushed the ft/set-impl branch 2 times, most recently from 888fb4a to d3e136d Compare February 24, 2026 23:48
@facutuesca facutuesca marked this pull request as ready for review February 24, 2026 23:52
Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
@facutuesca
Copy link
Contributor Author

Rebased and changed to use the new custom write errors.

src/types.rs Outdated
#[inline]
fn parse_data(data: &'a [u8]) -> ParseResult<Set<'a>> {
parse(data, |p| {
let mut last_element: Option<Tlv<'a>> = None;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we de-dupe this between this and SetOf?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. SetOf<T> does an extra step that we don't do for Set : for each element, it calls T::parse(element).
The helper function added that deduplicates the logic that checks the order takes a callback so that SetOf can still do that, and Set just passes a no-op.

/// Validates that TLV elements in a SET are in DER canonical order.
/// Calls `per_element` for each successfully read TLV, passing the
/// element and its zero-based index.
fn validate_set_ordering<'a>(
    p: &mut Parser<'a>,
    mut per_element: impl FnMut(Tlv<'a>, usize) -> ParseResult<()>,
) -> ParseResult<()> {

Signed-off-by: Facundo Tuesca <facundo.tuesca@trailofbits.com>
@alex alex merged commit 85f036c into alex:main Feb 25, 2026
13 checks passed
@facutuesca facutuesca deleted the ft/set-impl branch February 25, 2026 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for SET

2 participants