-
Notifications
You must be signed in to change notification settings - Fork 32
Unify mechanism traits #162
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
Conversation
|
I like that |
8624e88 to
32d3d9f
Compare
|
Rebased onto main and updated so that we now only define a single list of implemented mechanisms. |
|
@sosthene-nitrokey @daringer Can you please review this so that we can include it in the next release? |
This patch combines the operation traits that were previously used to call mechanism implementations into a single MechanismImpl trait. This has several advantages: - We can use a macro to implement the dispatch from the Mechanism enum, removing boilerplate code from the reply_to implementation. - To implement an operation for a mechanism, it is now sufficient to override the respective trait method. It is no longer necessary to also update reply_to. - The need to annotate all mechanism methods with #[inline(never)] to avoid producing a huge reply_to function (see the comment in mechanisms.rs) is reduced as we can just mark the methods generated by the macro as #[inline(never)]. - This reduces the binary size required in the stable nitrokey-3-firmware by some kB.
This patch removes the manual mechanism enumeration in IMPLEMENTED_MECHANISMS and changes the rpc_trait! macro to also generate this constant so that it acts as a single source of truth. As a side effect, the IMPLEMENTED_MECHANISMS constant is moved from types to service and only available if the crypto-client feature is enabled.
This patch makes the mechanisms module private. The mechanism implementation can still be accessed using the Mechanism enum. This leads to a clenaer public API and triggers a compiler warning if the mapping between the Mechanism enum and the mechanism implementations is wrong (as the implementation would then be unused).
32d3d9f to
1408449
Compare
|
I don't really like Not a blocker. |
The paste dependency is unmaintained and not really necessary for our use case.
|
Unfortunately |
This patch combines the operation traits that were previously used to call mechanism implementations into a single MechanismImpl trait. This has several advantages: