Skip to content

Allow working with a non-finalizing Pkcs11 #290

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wiktor-k
Copy link
Collaborator

Hi folks,

There is much interest in a Pkcs11 that does not finalize the underlying implementation and I thought I'll try out one idea I had: splitting the Pkcs11 into an owning and ref structs (similarly to how Rust does with String and str). I've made the Pkcs11 finalize itself and the Pkcs11Impl just work on what's passed in. This way, folks that manage the lifecycle themselves can construct a new instance via Pkcs11Impl::new_unchecked which should resolve #208.

I've also dropped inner Arc from Pkcs11 (so that the concurrency is now managed by the client outside of Pkcs11) and made Session own a reference to the client. I'd further rename Pkcs11Impl into something like Pkcs11Ref but I want to keep the diff as small as possible, and in case you don't like it it's not worth the refactor.

See what you think about it @hug-dev and @Jakuje.

The alternative posted on Slack by @testingapisname is adding additional finalization flag: testingapisname@6a4e58d

@wiktor-k wiktor-k force-pushed the wiktor/allow-working-with-non-finalizing-pkcs11 branch from 0673f4e to e51d16f Compare June 23, 2025 11:45
@Jakuje
Copy link
Collaborator

Jakuje commented Jun 23, 2025

I do not have this use case and I do not feel knowledgeable enough of rust to be able to judge which of the approaches is better. But this one looks more straightforward, while the other more "bolted on top of the existing things".

Generally, I think it is a good idea, especially when we have people asking for this.

@wiktor-k
Copy link
Collaborator Author

Yep, good point. I've pinged folks in #208 to check if this makes sense (I'd rather avoid making changes without backing approval from real-world users).

Thanks for your help!

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.

Add a new constructor that does not call C_Finalize when dropped
2 participants