Cryptoki: a cryptographic Token Interface



Download 360.55 Kb.
Page83/196
Date22.12.2023
Size360.55 Kb.
#63026
1   ...   79   80   81   82   83   84   85   86   ...   196
v201-95
pkcs11-base-v2.40-cos01
C_WaitForSlotEvent waits for a slot event, such as token insertion or token removal, to occur. flags determines whether or not the C_WaitForSlotEvent call blocks (i.e., waits for a slot event to occur); pSlot points to a location which will receive the ID of the slot that the event occurred in. pReserved is reserved for future versions; for this version of Cryptoki, it should be NULL_PTR.
At present, the only flag defined for use in the flags argument is CKF_DONT_BLOCK:
#define CKF_DONT_BLOCK 1
Internally, each Cryptoki application has a flag for each slot which is used to track whether or not any unrecognized events involving that slot have occurred. When an application initially calls C_Initialize, every slot’s event flag is cleared. Whenever a slot event occurs, the flag corresponding to the slot in which the event occurred is set.
If C_WaitForSlotEvent is called with the CKF_DONT_BLOCK flag set in the flags argument, and some slot’s event flag is set, then that event flag is cleared, and the call returns with the ID of that slot in the location pointed to by pSlot. If more than one slot’s event flag is set at the time of the call, one such slot is chosen by the library to have its event flag cleared and to have its slot ID returned.
If C_WaitForSlotEvent is called with the CKF_DONT_BLOCK flag set in the flags argument, and no slot’s event flag is set, then the call returns with the value CKR_NO_EVENT. In this case, the contents of the location pointed to by pSlot when C_WaitForSlotEvent are undefined.
If C_WaitForSlotEvent is called with the CKF_DONT_BLOCK flag clear in the flags argument, then the call behaves as above, except that it will block. That is, if no slot’s event flag is set at the time of the call, C_WaitForSlotEvent will wait until some slot’s event flag becomes set. If a thread of an application has a C_WaitForSlotEvent call blocking when another thread of that application calls C_Finalize, the C_WaitForSlotEvent call returns with the value CKR_CRYPTOKI_NOT_INITIALIZED.
Although the parameters supplied to C_Initialize can in general allow for safe multi-threaded access to a Cryptoki library, C_WaitForSlotEvent is exceptional in that the behavior of Cryptoki is undefined if multiple threads of a single application make simultaneous calls to C_WaitForSlotEvent.
Return values: CKR_CRYPTOKI_NOT_INITIALIZED, CKR_FUNCTION_FAILED, CKR_GENERAL_ERROR, CKR_HOST_MEMORY, CKR_NO_EVENT, CKR_OK.
Example:
CK_FLAGS flags = 0;
CK_SLOT_ID slotID;
CK_SLOT_INFO slotInfo;

.
.
.


/* Block and wait for a slot event */
rv = C_WaitForSlotEvent(flags, &slotID, NULL_PTR);
assert(rv == CKR_OK);

/* See what’s up with that slot */


rv = C_GetSlotInfo(slotID, &slotInfo);
assert(rv == CKR_OK);
.
.
.
1   ...   79   80   81   82   83   84   85   86   ...   196




The database is protected by copyright ©ininet.org 2024
send message

    Main page