Open Nicceboy opened 2 weeks ago
The issue here is duplicate tags which get overwritten when creating field_bitfield
mapping and this results to wrong preamble bits.
@XAMPPRocky what could be the best approach here? I guess the above is valid ASN.1 syntax, so we should be able to encode and decode it.
I was thinking of adding field_index
field for Tag
type, so in untagged sequence/set we can distinct duplicate tags in sequence in encoder and decoder logic.
My initial question is, why not fix the field_bitfield
to allow this to work instead of adding a new field?
My initial question is, why not fix the
field_bitfield
to allow this to work instead of adding a new field?
I tried to do that at first, but it seems that there isn't enough information available to detect duplicate tags from different fields.
Whenever something is encoded,
pub fn set_bit(&mut self, tag: Tag, bit: bool) {
self.field_bitfield.entry(tag).and_modify(|(_, b)| *b = bit);
is called, and only Tag
type is accessible from encoding methods. Currently, it does not carry enough information.
What if the map was (Tag, usize)
? As in it encodes the tag and the position?
This is the compiled macro for this case
#[allow(clippy::mutable_key_type)]
impl rasn::Encode for SequenceOptionals {
fn encode_with_tag_and_constraints<'constraints, EN: rasn::Encoder>(
&self,
encoder: &mut EN,
tag: rasn::Tag,
constraints: rasn::types::Constraints<'constraints>,
) -> core::result::Result<(), EN::Error> {
#[allow(unused)]
let __rasn_field_it = &self.it;
#[allow(unused)]
let __rasn_field_is = &self.is;
#[allow(unused)]
let __rasn_field_late = &self.late;
encoder
.encode_sequence::<Self, _>(tag, |encoder| {
self.it.encode(encoder)?;
self.is.encode(encoder)?;
self.late.encode(encoder)?;
Ok(())
})
.map(drop)
}
}
Maybe sequence encoder could actually carry current index based on the order there and then (Tag, usize)
is possible without changing trait signatures.
So another part of this, is do we need to fix this for SET
as well, that would prevent some ways in which this is handled.
I guess I was able to fix it and nothing else exploded. In SET
, unique tags seem to be mandatory so it was not an issue.
There is OER fix first, if that seems ok, in #279
OER/UPER/APER fails to encode Sequence with untagged and optional fields
Output: