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

Question about DER encoding discrepancy between versions (0.7 -> 0.8) #217

Closed
orthecreedence opened this issue Jan 18, 2024 · 1 comment · Fixed by #219
Closed

Question about DER encoding discrepancy between versions (0.7 -> 0.8) #217

orthecreedence opened this issue Jan 18, 2024 · 1 comment · Fixed by #219
Labels
area/codec Related to a new or existing ASN.1 codec. good first issue Good for newcomers help wanted Extra attention is needed kind/bug Something isn't working

Comments

@orthecreedence
Copy link
Contributor

Hi! I had some tests for my project to make sure the serialization format is preserved across project updates. I was initially only testing deserialization but recently made a change in my project that made testing serialization deterministically possible as well. The interesting thing is that I noticed the serialization format changed from when I wrote the test (this was back on v0.7).

I wrote a quick test to check this out and came up with two results:

#[derive(Debug, Clone, AsnType, Encode, Decode)]
#[rasn(choice)]
enum Tx {
    #[rasn(tag(explicit(0)))]
    Test,
    #[rasn(tag(explicit(1)))]
    Reset {
        #[rasn(tag(explicit(0)))]
        keys: Option<Vec<u32>>,
    }
}
let tx1 = Tx::Reset { keys: None };
let tx1_ser = rasn::der::encode(&tx1).unwrap();
println!("--- {:?}", tx1_ser);

In v0.7 this produces (https://lapo.it/asn1js/#oQIwAA):

[161, 2, 48, 0]

And in v0.8 this produces (https://lapo.it/asn1js/#oQQwAqAA):

[161, 4, 48, 2, 160, 0]

I'm not entirely sure which one "correct" now. It seems v0.8+ encode None as their own sequence instead of omitting the value...is this the desired behavior? From my (admittedly limited) understanding, OPTIONAL fields are omitted when they are blank.

@orthecreedence orthecreedence changed the title Question about encoding discrepancy between versions (0.7 -> 0.8) Question about DER encoding discrepancy between versions (0.7 -> 0.8) Jan 18, 2024
@XAMPPRocky
Copy link
Collaborator

Thank you for your issue! The best way to find out is to compare to another tool. IF the problem is indeed in the newer version, then we need to fix it. I don't have time to make a fix myself, but I'd be happy to review a PR fixing it 🙂

@XAMPPRocky XAMPPRocky added kind/bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers area/codec Related to a new or existing ASN.1 codec. labels Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codec Related to a new or existing ASN.1 codec. good first issue Good for newcomers help wanted Extra attention is needed kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants