- 
                Notifications
    You must be signed in to change notification settings 
- Fork 85
          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
base: main
Are you sure you want to change the base?
  
    Allow working with a non-finalizing Pkcs11
  
  #290
              Conversation
0673f4e    to
    e51d16f      
    Compare
  
    | 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. | 
| 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! | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this!!
The first commit makes sense: better to let the user decide if they want shared ownership with Arc or not! Makes it clearer in the tests using multiple threads as well.
| /// Initializes Pkcs11 using raw Pkcs11 object. | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// `pkcs11_lib` must point to a valid Pkcs11 object. | ||
| pub unsafe fn new_unchecked(pkcs11_lib: cryptoki_sys::Pkcs11) -> Result<Self> { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea here! Was only wondering if we could expand the documentation (and maybe change the name?) to make clear that this is done so that finalize is not called on Drop and maybe explain the use-case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added better docs... happy to hear suggestions about the naming though... new_non_finalizing? new_manage_your_own_lifecycle? I'm kind-of bad at naming 😅
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
e51d16f    to
    02deaf7      
    Compare
  
    | I think this is a step in the right direction, although I see follow-up work (just outlining here so I don't forget): 
 Phew 😅 hopefully I didn't forget about anything! | 
| 
 ahh that's a good point 😅 Seems like @testingapisname could also be a cheap solution with just a new finalization flag | 
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
Pkcs11into an owning and ref structs (similarly to how Rust does withStringandstr). I've made thePkcs11finalize itself and thePkcs11Impljust work on what's passed in. This way, folks that manage the lifecycle themselves can construct a new instance viaPkcs11Impl::new_uncheckedwhich 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 madeSessionown a reference to the client. I'd further renamePkcs11Implinto something likePkcs11Refbut 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