latchset / kryoptic

a pkcs#11 software token written in Rust
GNU General Public License v3.0
10 stars 4 forks source link

Consider tweaking the ffi bindings to add lifetimes #76

Open simo5 opened 2 months ago

simo5 commented 2 months ago

Many PKCS#11 structures carry "naked" pointers to other structures or buffers.

On the caller side there we can only hope the application calling in does the right thing, however when we call ourselves internally (in tests or when implementing complex chained functions) having lifetimes will allow the compiler to ensure we keep data around for the time necessary.

This is particularly useful for structures like CK_ATTRIBUTE which are useful to manipulate in helper functions, but require very careful management of the pointers to ensure the data is not some pointer allocated on the stack after we return from the helper.

Similarly actually for OSSL_PARAM when we call into openssl and want to use a hlper to fill in an array of params.