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 compile-time mechanism checks #192

Merged
merged 2 commits into from
Jan 6, 2025
Merged

Fix compile-time mechanism checks #192

merged 2 commits into from
Jan 6, 2025

Conversation

robin-nitrokey
Copy link
Member

This PR adds missing variants to trussed::types::IMPLEMENTED_MECHANISMS and makes it easier to validate the selected mechanisms at compile time.

@robin-nitrokey robin-nitrokey force-pushed the mechanism-check branch 2 times, most recently from 872f9ab to 0b44ea7 Compare December 20, 2024 16:08
@robin-nitrokey
Copy link
Member Author

Updated to use a macro to generate the Mechanism enum and to provide a const_eq function instead of #[repr(u8)] (because that does not work with empty enums).

core/src/types.rs Outdated Show resolved Hide resolved
To be able to compare mechanism variants in const contexts, we use
add a const_eq function.  And to be able to indicate which mechanism
is potentially missing, we add a const panic method that includes the
mechanism variant in the panic message.

To reduce the boilerplate code, we use a macro to generate the enum.
@robin-nitrokey robin-nitrokey merged commit 2cd3cee into main Jan 6, 2025
2 checks passed
@robin-nitrokey robin-nitrokey deleted the mechanism-check branch January 6, 2025 13:43
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