From 5335225619d8f2e9f80bee5ef24757ec4890ba82 Mon Sep 17 00:00:00 2001 From: Aaron Kaloti Date: Tue, 16 Jun 2026 16:35:22 -0700 Subject: [PATCH] Fix crash when closing sessions with vendor-specific user types --- pkcs11/_pkcs11.pyx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkcs11/_pkcs11.pyx b/pkcs11/_pkcs11.pyx index 27f692e2..85a8c7d6 100644 --- a/pkcs11/_pkcs11.pyx +++ b/pkcs11/_pkcs11.pyx @@ -892,14 +892,18 @@ cdef class Session(HasFuncList, types.Session): @property def user_type(self): - """User type for this session (:class:`pkcs11.constants.UserType`).""" - return UserType(self._user_type) + """User type for this session (:class:`pkcs11.constants.UserType` or :class:`int` for vendor-specific values).""" + try: + return UserType(self._user_type) + except ValueError: + # Return raw value for vendor-specific user types + return self._user_type def close(self): cdef CK_SESSION_HANDLE handle = self.handle cdef CK_RV retval - if self.user_type != UserType.NOBODY: + if self._user_type != CKU_USER_NOBODY: with nogil: retval = self.funclist.C_Logout(handle) assertRV(retval)