Open zaicruvoir1rominet opened 1 month ago
Hi @zaicruvoir1rominet , check out the classes here, which can be used:
with Session(slot) as session:
c_generate_key_ex(session, ...)
Nice !
Would you mind me updating the docs, to make these easier to find ?
Hi there !
I'm wondering if you would be open to augmenting
pycryptoki
with context managers (with block ...) support. This would allow exceptions to propagate normally inpycryptoki
code and make forgetting to close/logout/finalize/... functions or accidentally calling close/logout/finalize/... functions when you aren't supposed to impossible.Current situation
The above code would prevent
pycryptoki
'sc_finalize_ex
to properly execute.Potential solution
Make open/logout/initialize functions return context managers:
There is no need to call
c_finalize_ex
, it is automatically executed in case of an exception or when leaving thewith
block.(The context manager returned by
c_initialize_ex
would also be possible to be interpreted as a "normal" return value, in case user want to fetch this, and to avoid introducing breaking changes).