Skip to content

Commit 4ba54bf

Browse files
Micah N GorrellMatthiasValvekens
authored andcommitted
Properly handle the CK_UNAVAILABLE_INFORMATION return value when trying to read an attribute
1 parent d45957f commit 4ba54bf

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkcs11/_pkcs11.pxd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ cdef extern from '../extern/cryptoki.h':
151151
CK_TRUE,
152152
CK_FALSE,
153153

154+
cdef enum:
155+
CK_UNAVAILABLE_INFORMATION,
156+
CK_EFFECTIVELY_INFINITE,
157+
154158
cdef enum: # CK_FLAGS
155159
CKF_DONT_BLOCK,
156160
CKF_RW_SESSION,

pkcs11/_pkcs11.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,8 @@ class Object(types.Object):
915915
# Find out the attribute size
916916
with nogil:
917917
retval = _funclist.C_GetAttributeValue(handle, obj, &template, 1)
918+
if retval == CK_UNAVAILABLE_INFORMATION:
919+
return None
918920
assertRV(retval)
919921

920922
if template.ulValueLen == 0:
@@ -927,6 +929,8 @@ class Object(types.Object):
927929
# Request the value
928930
with nogil:
929931
retval = _funclist.C_GetAttributeValue(handle, obj, &template, 1)
932+
if retval == CK_UNAVAILABLE_INFORMATION:
933+
return None
930934
assertRV(retval)
931935

932936
return _unpack_attributes(key, value)

0 commit comments

Comments
 (0)