Uh oh!
There was an error while loading. Please reload this page.
support private tags and tag numbers >30 that are stored in long form - #1416
support private tags and tag numbers >30 that are stored in long form#1416kamulos wants to merge 4 commits into
Conversation
Uh oh!
There was an error while loading. Please reload this page.
[Spoiler] Unrelated to >30 tag breaking change
I've made it generic for my use case. /// Application classtypeApplication<T,constTAG:u16> = CustomClass<T,TAG,0b01>;/// Context-specific classtypeContextSpecific<T,constTAG:u16> = CustomClass<T,TAG,0b10>;/// Private classtypePrivate<T,constTAG:u16> = CustomClass<T,TAG,0b11>;/// Application, Context-specific or Private class field which wraps an owned inner value.////// This type decodes/encodes a field which is specific to a particular context/// and is identified by a [`TagNumber`].#[derive(Copy,Clone,Debug,Eq,PartialEq,PartialOrd,Ord)]pubstructCustomClass<T,constTAG:u16,constCLASS:u8>{/// Tag mode: `EXPLICIT` VS `IMPLICIT`.pubtag_mode:TagMode,/// Value of the field.pubvalue:T,}Shouldn't |
dishmaker
commented
Jun 10, 2024
This crate is still unusable for the European Tachograph regulation. There are many 2-byte tags. https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=celex%3A02016R0799-20200226
|
baloo
commented
Jun 11, 2024
@dishmaker we're still open for breaking changes in this release cycle. There is a legitimate use-case, PRs are welcome! |
kamulos
commented
Jun 25, 2024
Sorry for the slow reaction. In a week I am back and try to get in some more progress here. |
tarcieri
commented
Aug 18, 2024
@kamulos I've finished making the other changes I consider blockers for this one, though it's created quite a few conflicts. If you can get this PR green though, I can make it a priority for the next to merge. I don't expect there will be many other major changes to |
kamulos
commented
Sep 13, 2024
@tarcieri Thanks for your work ❤️ And sorry for being very slow, the workload at the job was high and I also had vacations. Currently we are actually releasing this code into production and things will calm down from here. So I will get back to this next week and hopefully get some version ready that is good quality. |
tarcieri
commented
Sep 13, 2024
@kamulos no worries, we'd like to do a release "soon", but that's probably in a month or two so you have some time |
39e8b97 to
1f43a08Comparekamulos
commented
Oct 2, 2024
@tarcieri I rebased and polished the implementation. The unit tests for the But other than that I think it is ready for review. 👍 There are some noteworthy points:
|
[Spoiler] Unrelated to >30 tags
Well, I also need I think the best solution is using generics: pubtypeApplicationExplicit<constTAG:u16,T> = CustomClassExplicit<T,TAG,CLASS_APPLICATION>;pubtypeContextSpecificExplicit<constTAG:u16,T> = CustomClassExplicit<T,TAG,CLASS_CONTEXT_SPECIFIC>;pubtypePrivateExplicit<constTAG:u16,T> = CustomClassExplicit<T,TAG,CLASS_PRIVATE>;pubtypeApplicationImplicit<constTAG:u16,T> = CustomClassImplicit<T,TAG,CLASS_APPLICATION>;pubtypeContextSpecificImplicit<constTAG:u16,T> = CustomClassImplicit<T,TAG,CLASS_CONTEXT_SPECIFIC>;pubtypePrivateImplicit<constTAG:u16,T> = CustomClassImplicit<T,TAG,CLASS_PRIVATE>;/// EXPLICIT#[derive(Copy,Clone,Debug,Eq,PartialEq,PartialOrd,Ord)]pubstructCustomClassExplicit<T:for<'a>Decode<'a>,constTAG:u16,constCLASS:u8>{pubvalue:T,}/// IMPLICIT#[derive(Copy,Clone,Debug,Eq,PartialEq,PartialOrd,Ord)]pubstructCustomClassImplicit<T:for<'a>DecodeValue<'a>,constTAG:u16,constCLASS:u8>{pubvalue:T,}pubconstCLASS_APPLICATION:u8 = 0b01000000;pubconstCLASS_CONTEXT_SPECIFIC:u8 = 0b10000000;pubconstCLASS_PRIVATE:u8 = 0b11000000; |
dishmaker
commented
Oct 9, 2024
I've fixed all dependencies and added these 3 custom tags as generic ones :) |
tarcieri
commented
Jan 21, 2025
@kamulos if you are still interested in this, I would prefer a much more minimal PR which only changes the handling of the |
1f43a08 to
ad41d37Comparekamulos
commented
Feb 13, 2025
@tarcieri thanks for the message. I looked into it, rebased my commit and removed the stuff in a new commit. With my last commit I added a three unit test cases, where the decoder is pretty forgiving at the moment. The second test case ("universal tag in long form") might be ok, but the other two accept invalid |
tarcieri
commented
Feb 13, 2025
kamulos
commented
Feb 14, 2025
@tarcieri Yeah, that PR is good. But obviously, the issues I codified in my test cases here affect that one too, because the code is a copy. So you might still want to have a look at the cases. The adjusted Test case in the other PR, where they put in ReasonFlags::from_der(&hex!("FF03079F80"));` is what made me realize that there might still be questions about the exact behavior open. |
tarcieri
commented
Feb 14, 2025
turbocool3r
commented
Feb 14, 2025
tarcieri
commented
May 5, 2025
Ended up going with #1651 instead |
closes#1381
This PR implements two things:
PRIVATEtags be annotated like context specific ones in the derive macrosCurrent State
Currently this is a draft to get feedback on the chosen approach. This code is in use in my project and works correctly for it's use-case: a lot of private tags in a deep hierarchy of choices and sequences.
For the most part this code should be in a state to be reviewed. There are a few parts that are still lacking:
privatemodule, that is basically just a copy of thecontext_sensitivemoduleOverview
TagNumberis now represented by anu16. This should be enough for any use-case imaginable, but also small enough to be embedded-friendly. It's content is nowpubinstead ofpub(super). This was necessary becauseder_derivewants to match against constantTagNumbers. In general having this public should not be an issue, because all2^16tag numbers are now valid and it is not possible to create an invalid state by having access to theu16.Also the
PrivateandPrivateReftypes exist now. In the derive macrosprivatecan be annotated in the same way ascontext_specific. Internally this is represented asclass: Option<Class>instead ofcontext_sensitive: Option<TagNumber>.Breaking changes that I found no way to avoid are:
TagNumber::new()andTagNumber::value()useu16nowu8forTagandTagNumberdo not make sense anymore, this also applies toTag::octet()Readertrait now needs a function to peek multiple bytes in advance to be able to peek a tag (Reader::peek_offset())Length::for_tlv()just assumed, that a tag is always one byte, it now somehow needs to know about the specific tag we are looking at