-
Notifications
You must be signed in to change notification settings - Fork 14
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
Consume embedded SEQUENCE in a clean way #33
Comments
You have multiple options If you know the definition of your types, the recommended solution is to create a struct for each sequence and derive parsers to be able to call
Resulting code would look like: #[derive(Debug, PartialEq, DerSequence)]
pub struct MyType {
a: TypeA,
b: TypeB,
}
#[derive(Debug, PartialEq, DerSequence)]
pub struct TypeA {
field1: u32,
...
}
let (rem, obj) = MyType::from_der(input)?; If you can't derive or prefer to use manual parsers, the solution you describe will work, but it will not be idiomatic.
let (rem, seq) = Sequence::from_der(input)?;
let (inner_rem, type_a) = Sequence::from_der(seq.content)?;
let (inner_rem, type_b) = Sequence::from_der(inner_rem)?;
let (rem, seq) = Sequence::from_der(input)?;
let (inner_rem, type_a) = Sequence::from_der_and_then(seq.content, |i| {
let (rem2, a) = u32::from_der(input)?;
...
Ok(...)
})?; let (inner_rem, type_b) = Sequence::from_der(inner_rem)?;
let (rem, seq) = Sequence::from_der(input)?;
let (inner_rem, type_a) = TypeA::from_der(seq.content)?;
})?;
|
Thanks for your answer ! I will check for the idiomatic way if my use case grows. For now, I only need to retrieve a few fields in the BER data |
I have a BER schema which looks like the following :
I try to retrieve fields that are located in typeA SEQUENCE, how can I inspect it in a way to deal with errors, i.e. is it possible to do something like the following :
Is it the right to do that ? I'm not able to find the correct code to write in order to run that.
Thanks in advance
The text was updated successfully, but these errors were encountered: