Nitrokey/nethsm-pkcs11

refactor functions in the pkcs11/api folder

nponsard opened this issue · 1 comments

The idea would be to move the logic out of these functions, only the mapping of the input and the output would be done here.

This would be only a developer quality of life change and is purely optional since everything is already implemented.

From #92:

Some complexity in the API functions comes from the custom error handling with CK_RV. It’s probably not worth to change it now that almost everything is implemented, but a helper macro that makes it possible to write Result<(), CK_RV> functions instead could be more ergonomic. Alternatively, the logic could be moved to safe functions returning Result<_, CK_RV> and the extern "C" functions only perform the mapping between the input and output.

This would allow:

  • Functions that return Result<(), CK_RV> for example to replace the ensure_init macro in #165
  • If the rust API explicitly takes a &Device and references to the other statics it would allow better management of the statics and make testing with custom values easier. The statics would only be accessed in one place.