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

Not handling the encoding of explicit tags when a default value is present #418

Open
jusbeyer opened this issue Mar 6, 2025 · 0 comments

Comments

@jusbeyer
Copy link

jusbeyer commented Mar 6, 2025

Recently rasn added support for explicit tags in an ASN.1 Structure. When this support was added, though, it does not appear that anything was added to handle the non-encoding default values.

Per ITU standard, this value should not be present during encoding. Since decoding automatically sets the default value, when not present, and will preserve the value, if provided, a fix should be implemented and will be backwards compatible (assuming downstream systems correctly handle this).

Example code:

use rasn::prelude::*;

#[derive(AsnType, Decode, Debug, Encode, PartialEq)]
pub struct SequenceWithMultiDefault {
    #[rasn(tag(explicit(application, 1)), default="default_bool")]
    b: bool,
    #[rasn(tag(explicit(application, 2)), default="default_bool")]
    b2: bool,
}
pub fn default_bool() -> bool {
    true
}

fn main() {
    let seq = SequenceWithMultiDefault{ b: true, b2: false };
    let encoded = rasn::der::encode(&seq).unwrap();
    println!("{:02x?}", encoded);
}

Produces:

[30, 0a, 61, 03, 01, 01, ff, 62, 03, 01, 01, 00]

Should Produce (Note: The first tagged field is not present):

[30, 05, 62, 03, 01, 01, 00]
jusbeyer added a commit to jusbeyer/rasn that referenced this issue Mar 6, 2025
… values with explicit tags. Adding test cases for this in a couple different scenarios.
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

No branches or pull requests

1 participant