Skip to content
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

Introduce lib finalize method #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pkcs11/_pkcs11.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,8 @@ cdef class lib:
pkcs11.types.
"""

cdef bint _finalized

cdef public str so
cdef public str manufacturer_id
cdef public str library_description
Expand Down Expand Up @@ -1509,6 +1511,7 @@ cdef class lib:
assertRV(_funclist.C_Initialize(NULL))

def __init__(self, so):
self._finalized = False
self.so = so
cdef CK_INFO info

Expand Down Expand Up @@ -1648,14 +1651,22 @@ cdef class lib:
return Slot(self, slot_id, slotDescription, manufacturerID,
info.hardwareVersion, info.firmwareVersion, info.flags)

def finalize(self):
if _funclist != NULL and not self._finalized:
with nogil:
assertRV(_funclist.C_Finalize(NULL))
self._finalized = True

def reinitialize(self):
if _funclist != NULL:
with nogil:
assertRV(_funclist.C_Finalize(NULL))
if not self._finalized:
assertRV(_funclist.C_Finalize(NULL))
assertRV(_funclist.C_Initialize(NULL))
self._finalized = False

def __dealloc__(self):
if _funclist != NULL:
if _funclist != NULL and not self._finalized:
with nogil:
assertRV(_funclist.C_Finalize(NULL))

Expand Down