@@ -253,6 +253,31 @@ class Slot(types.Slot):
253253class Token (types .Token ):
254254 """Extend Token with implementation."""
255255
256+ def init_token (self , token_label , so_pin ):
257+ cdef CK_SLOT_ID slot_id = self .slot .slot_id
258+ cdef CK_UTF8CHAR * pin_data
259+ cdef CK_ULONG pin_length
260+ cdef CK_UTF8CHAR * label
261+
262+ if token_label is None or so_pin is None :
263+ raise ArgumentsBad ("Set both `token_label` and `so_pin`" )
264+
265+ pin = so_pin .encode ('utf-8' )
266+ tlabel = token_label .encode ('utf-8' )
267+
268+ if pin and tlabel :
269+ pin_data = pin
270+ pin_length = len (pin )
271+ label = tlabel
272+
273+ with nogil :
274+ assertRV (_funclist .C_InitToken (slot_id , pin_data , pin_length ,
275+ label ))
276+
277+ return True
278+
279+ return False
280+
256281 def open (self , rw = False , user_pin = None , so_pin = None ):
257282 cdef CK_SLOT_ID slot_id = self .slot .slot_id
258283 cdef CK_SESSION_HANDLE handle
@@ -373,6 +398,27 @@ def merge_templates(default_template, *user_templates):
373398class Session (types .Session ):
374399 """Extend Session with implementation."""
375400
401+ def init_pin (self , user_pin ):
402+ cdef CK_OBJECT_HANDLE handle = self ._handle
403+ cdef CK_UTF8CHAR * pin_data
404+ cdef CK_ULONG pin_length
405+
406+ if user_pin is None :
407+ raise ArgumentsBad ("Set `user_pin`" )
408+
409+ pin = user_pin .encode ('utf-8' )
410+
411+ if pin :
412+ pin_data = pin
413+ pin_length = len (pin )
414+
415+ with nogil :
416+ assertRV (_funclist .C_InitPIN (handle , pin_data , pin_length ))
417+
418+ return True
419+
420+ return False
421+
376422 def close (self ):
377423 cdef CK_OBJECT_HANDLE handle = self ._handle
378424
0 commit comments