Skip to content
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

Derive a SEQUENCE OF SEQUENCE? #232

Closed
joshwatson opened this issue Nov 15, 2021 · 7 comments
Closed

Derive a SEQUENCE OF SEQUENCE? #232

joshwatson opened this issue Nov 15, 2021 · 7 comments

Comments

@joshwatson
Copy link

joshwatson commented Nov 15, 2021

I was able to derive some structs that deserialize correctly, but I'm struggling to figure out how to represent a SEQUENCE OF SEQUENCE in a struct. Is there an example of this anywhere? Is it possible, or do I need to write my own code with a d.read_element::<asn1::SequenceOf>() to do this?

@alex
Copy link
Owner

alex commented Nov 15, 2021

Sure, this is very much possible!

#[derive(asn1::Asn1Read, asn1::Asn1Write, Hash, PartialEq, Clone)]
pub(crate) struct TbsCertificate<'a> {
    // ...
    extensions: Option<asn1::SequenceOf<'a, Extension<'a>>>,
}

#[derive(asn1::Asn1Read, asn1::Asn1Write, PartialEq, Hash, Clone)]
pub(crate) struct Extension<'a> {
    pub(crate) extn_id: asn1::ObjectIdentifier<'a>,
    #[default(false)]
    pub(crate) critical: bool,
    pub(crate) extn_value: &'a [u8],
}

Does that answer your question?

@alex
Copy link
Owner

alex commented Nov 15, 2021

Or if you've really just got SEQUENCE OF SEQUENCE (i.e. no more specific type), you can have asn1::SequenceOf<'a, asn1::Sequence<'a>>

@joshwatson
Copy link
Author

I believe this does answer my question, I'll try this out. Thanks!!

@joshwatson
Copy link
Author

Yep looks like it worked, thanks so much!

@alex
Copy link
Owner

alex commented Nov 15, 2021

My pleasure! If you have suggestions for how the docs could be more clear, please shout them out!

@joshwatson
Copy link
Author

I do have one more question! Is it possible to create a new SequenceOf from like a Vec or similar that I can then serialize back to asn1? I've successfully parsed asn1 and gotten a SequenceOf from it, but I can't figure out how to modify the data within and round-trip it back to asn1; if I iterate over it, it of course consumes the elements and I end up serializing an empty SequenceOf back to asn1.

@alex
Copy link
Owner

alex commented Nov 30, 2021 via email

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

No branches or pull requests

2 participants