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

Unify and Improve error handling of restricted strings #269

Merged
merged 8 commits into from
Jul 9, 2024

Conversation

Nicceboy
Copy link
Contributor

Fixes #260

Adds alphabet_name function for StaticPermittedAlphabet trait for better error messages.

@Nicceboy
Copy link
Contributor Author

Actually error reporting isn't that good. Might be better to give the failed value also in the error message like in other codecs

@Nicceboy Nicceboy changed the title oer: improve error handling of restricted strings draft: oer: improve error handling of restricted strings Jun 18, 2024
@XAMPPRocky
Copy link
Collaborator

Actually error reporting isn't that good. Might be better to give the failed value also in the error message like in other codecs

Yes, hough I think it might be good to have a unified error across all codecs for strings, so this logic can be better shared, and if codecs can provide more context they can wrap the error type.

@@ -10,6 +10,7 @@ pub(crate) trait StaticPermittedAlphabet: Sized + Default {
const CHARACTER_SET: &'static [u32];
const CHARACTER_WIDTH: u32 = crate::num::log2(Self::CHARACTER_SET.len() as i128);

fn alphabet_name() -> &'static str;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better as a enum, and have it as a associated const instead of a fn.

@Nicceboy
Copy link
Contributor Author

Related to this #185, maybe it can be handled in the same time.

@XAMPPRocky
Copy link
Collaborator

Thank you for your PR! Looks good to me, I notice a lot of commented out code, can that code be removed or is there a reason it's commented out?

@Nicceboy
Copy link
Contributor Author

Nicceboy commented Jul 8, 2024

I was just finishing it, some small cleaning still to do.

I unified all the string types, so that they implemented StaticPermittedAlphabet. Also for Teletex type while the characters itself are not implemented.

I had to wrap all the errors behind PermittedAlphabetError, otherwise it was too difficult to implement (For example, there can be both constraint-related errors or string-type related errors.)

Also all TryFrom, From and Deref implementations are done with macros for all the types same time now.

@Nicceboy
Copy link
Contributor Author

Nicceboy commented Jul 8, 2024

Invalid restricted string error, for example, should look something like this now:

---- coer::tests::invalid_ia5_oer stdout ----
[src/coer.rs:697:9] e = DecodeError {
    kind: PermittedAlphabetError {
        reason: InvalidRestrictedString {
            source: InvalidIA5String(
                InvalidIA5String {
                    character: 129,
                },
            ),
        },
    },
    codec: Coer,
}

@Nicceboy Nicceboy changed the title draft: oer: improve error handling of restricted strings Unify and Improve error handling of restricted strings Jul 8, 2024
@Nicceboy
Copy link
Contributor Author

Nicceboy commented Jul 8, 2024

I think it is ready now. Not sure what is the performance since all characters on restricted strings are verified now in every codec.

@XAMPPRocky
Copy link
Collaborator

Thank you for your PR!

@XAMPPRocky XAMPPRocky merged commit d301ac0 into librasn:main Jul 9, 2024
65 checks passed
@github-actions github-actions bot mentioned this pull request Jul 9, 2024
@Nicceboy Nicceboy deleted the fix-260 branch July 9, 2024 17:18
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.

ia5 string decoding debug assertion reached from OER
2 participants