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

Fix/constrained extension #156

Merged
merged 5 commits into from
Sep 14, 2023
Merged

Conversation

6d7a
Copy link
Member

@6d7a 6d7a commented Sep 6, 2023

I ran into a problem with constrained extension additions the other day. I represented the following ASN1 snippet...

TestSequence ::= SEQUENCE { 
     hello OCTET STRING (SIZE(0..8)),
     ...,
     world INTEGER(0..9) DEFAULT 8
}

...using rasn as...

#[derive(AsnType, Debug, Clone, Decode, Encode, PartialEq)]
#[non_exhaustive]
struct TestSequence {
      #[rasn(size("0..=8"))]
      hello: OctetString,
      #[rasn(
            extension_addition,
            value("0..=9"),
            default = "test_sequence_world_default"
      )]
      world: u8,
}

fn test_sequence_world_default() -> u8 {
     8
}

...and discovered that an encoding-decoding round trip fails. I did some digging and it turned out that the decoder does not take constraints into account when dealing with extension additions. This PR provides the test case above and should fix the issue. The crucial fix is in the extension addition function of the per-decoder in src/per/de.rs, where I am passing along constraint information.

@6d7a
Copy link
Member Author

6d7a commented Sep 7, 2023

I also added the encode_default_with_constraints that is invoked in macros/src/config.rs:876.

@XAMPPRocky
Copy link
Collaborator

Thank you for your PR and congrats on your first contribution! I thought I had done this but I realised I mostly focused on constraints through the type system.

@XAMPPRocky XAMPPRocky merged commit fd2f3e6 into librasn:main Sep 14, 2023
68 checks passed
@github-actions github-actions bot mentioned this pull request Sep 2, 2023
@github-actions github-actions bot mentioned this pull request Sep 22, 2023
@github-actions github-actions bot mentioned this pull request Oct 10, 2023
@6d7a 6d7a deleted the fix/constrained-extension branch April 16, 2024 09:26
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

Successfully merging this pull request may close these issues.

2 participants