You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm wondering if you would be open to augmenting pycryptoki with context managers (with block ...) support. This would allow exceptions to propagate normally in pycryptoki 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
importpycryptoki.session_managementpycryptoki.session_management.c_initialize_ex()
# ... some code ...raiseValueError("There's a problem here !")
# ... some code ...pycryptoki.session_management.c_finalize_ex()
The above code would prevent pycryptoki's c_finalize_ex to properly execute.
Potential solution
Make open/logout/initialize functions return context managers:
importpycryptoki.session_managementwithpycryptoki.session_management.c_initialize_ex():
# ... some code ...raiseValueError("There's a problem here !")
# ... some code ...
There is no need to call c_finalize_ex, it is automatically executed in case of an exception or when leaving the with 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).
The text was updated successfully, but these errors were encountered:
zaicruvoir1rominet
changed the title
Pythonic begin/end interface (adding "with" support)
Pythonic open/close interface (adding "with" support)
Aug 14, 2024
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).The text was updated successfully, but these errors were encountered: