Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
instance.c File Reference
#include "ck.h"

Go to the source code of this file.

Classes

struct  NSSCKFWInstanceStr

Functions

NSS_IMPLEMENT NSSCKFWInstance * nssCKFWInstance_Create (CK_C_INITIALIZE_ARGS_PTR pInitArgs, CryptokiLockingState LockingState, NSSCKMDInstance *mdInstance, CK_RV *pError)
NSS_IMPLEMENT CK_RV nssCKFWInstance_Destroy (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT NSSCKMDInstance * nssCKFWInstance_GetMDInstance (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT NSSArena * nssCKFWInstance_GetArena (NSSCKFWInstance *fwInstance, CK_RV *pError)
NSS_IMPLEMENT CK_BBOOL nssCKFWInstance_MayCreatePthreads (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT NSSCKFWMutex * nssCKFWInstance_CreateMutex (NSSCKFWInstance *fwInstance, NSSArena *arena, CK_RV *pError)
NSS_IMPLEMENT NSSUTF8nssCKFWInstance_GetConfigurationData (NSSCKFWInstance *fwInstance)
CK_C_INITIALIZE_ARGS_PTR nssCKFWInstance_GetInitArgs (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT CK_SESSION_HANDLE nssCKFWInstance_CreateSessionHandle (NSSCKFWInstance *fwInstance, NSSCKFWSession *fwSession, CK_RV *pError)
NSS_IMPLEMENT NSSCKFWSession * nssCKFWInstance_ResolveSessionHandle (NSSCKFWInstance *fwInstance, CK_SESSION_HANDLE hSession)
NSS_IMPLEMENT void nssCKFWInstance_DestroySessionHandle (NSSCKFWInstance *fwInstance, CK_SESSION_HANDLE hSession)
NSS_IMPLEMENT CK_SESSION_HANDLE nssCKFWInstance_FindSessionHandle (NSSCKFWInstance *fwInstance, NSSCKFWSession *fwSession)
NSS_IMPLEMENT CK_OBJECT_HANDLE nssCKFWInstance_CreateObjectHandle (NSSCKFWInstance *fwInstance, NSSCKFWObject *fwObject, CK_RV *pError)
NSS_IMPLEMENT NSSCKFWObject * nssCKFWInstance_ResolveObjectHandle (NSSCKFWInstance *fwInstance, CK_OBJECT_HANDLE hObject)
NSS_IMPLEMENT CK_RV nssCKFWInstance_ReassignObjectHandle (NSSCKFWInstance *fwInstance, CK_OBJECT_HANDLE hObject, NSSCKFWObject *fwObject)
NSS_IMPLEMENT void nssCKFWInstance_DestroyObjectHandle (NSSCKFWInstance *fwInstance, CK_OBJECT_HANDLE hObject)
NSS_IMPLEMENT CK_OBJECT_HANDLE nssCKFWInstance_FindObjectHandle (NSSCKFWInstance *fwInstance, NSSCKFWObject *fwObject)
NSS_IMPLEMENT CK_ULONG nssCKFWInstance_GetNSlots (NSSCKFWInstance *fwInstance, CK_RV *pError)
NSS_IMPLEMENT CK_VERSION nssCKFWInstance_GetCryptokiVersion (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT CK_RV nssCKFWInstance_GetManufacturerID (NSSCKFWInstance *fwInstance, CK_CHAR manufacturerID[32])
NSS_IMPLEMENT CK_ULONG nssCKFWInstance_GetFlags (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT CK_RV nssCKFWInstance_GetLibraryDescription (NSSCKFWInstance *fwInstance, CK_CHAR libraryDescription[32])
NSS_IMPLEMENT CK_VERSION nssCKFWInstance_GetLibraryVersion (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT CK_BBOOL nssCKFWInstance_GetModuleHandlesSessionObjects (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT NSSCKFWSlot ** nssCKFWInstance_GetSlots (NSSCKFWInstance *fwInstance, CK_RV *pError)
NSS_IMPLEMENT NSSCKFWSlot * nssCKFWInstance_WaitForSlotEvent (NSSCKFWInstance *fwInstance, CK_BBOOL block, CK_RV *pError)
NSS_IMPLEMENT NSSCKMDInstance * NSSCKFWInstance_GetMDInstance (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT NSSArena * NSSCKFWInstance_GetArena (NSSCKFWInstance *fwInstance, CK_RV *pError)
NSS_IMPLEMENT CK_BBOOL NSSCKFWInstance_MayCreatePthreads (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT NSSCKFWMutex * NSSCKFWInstance_CreateMutex (NSSCKFWInstance *fwInstance, NSSArena *arena, CK_RV *pError)
NSS_IMPLEMENT NSSUTF8NSSCKFWInstance_GetConfigurationData (NSSCKFWInstance *fwInstance)
NSS_IMPLEMENT
CK_C_INITIALIZE_ARGS_PTR 
NSSCKFWInstance_GetInitArgs (NSSCKFWInstance *fwInstance)

Class Documentation

struct NSSCKFWInstanceStr

Definition at line 98 of file instance.c.

Collaboration diagram for NSSCKFWInstanceStr:
Class Members
NSSArena * arena
NSSUTF8 * configurationData
CK_VERSION cryptokiVersion
NSSCKFWSlot ** fwSlotList
CK_C_INITIALIZE_ARGS initArgs
CK_ULONG lastObjectHandle
CK_ULONG lastSessionHandle
NSSUTF8 * libraryDescription
CK_VERSION libraryVersion
CryptokiLockingState LockingState
NSSUTF8 * manufacturerID
CK_BBOOL mayCreatePthreads
NSSCKMDInstance * mdInstance
NSSCKMDSlot ** mdSlotList
CK_BBOOL moduleHandlesSessionObjects
NSSCKFWMutex * mutex
CK_ULONG nSlots
nssCKFWHash * objectHandleHash
CK_C_INITIALIZE_ARGS_PTR pInitArgs
nssCKFWHash * sessionHandleHash

Function Documentation

NSS_IMPLEMENT NSSCKFWInstance* nssCKFWInstance_Create ( CK_C_INITIALIZE_ARGS_PTR  pInitArgs,
CryptokiLockingState  LockingState,
NSSCKMDInstance *  mdInstance,
CK_RV pError 
)

Definition at line 194 of file instance.c.

{
  NSSCKFWInstance *fwInstance;
  NSSArena *arena = (NSSArena *)NULL;
  CK_ULONG i;
  CK_BBOOL called_Initialize = CK_FALSE;

#ifdef NSSDEBUG
  if( (CK_RV)NULL == pError ) {
    return (NSSCKFWInstance *)NULL;
  }

  if( (NSSCKMDInstance *)NULL == mdInstance ) {
    *pError = CKR_ARGUMENTS_BAD;
    return (NSSCKFWInstance *)NULL;
  }
#endif /* NSSDEBUG */

  arena = NSSArena_Create();
  if( (NSSArena *)NULL == arena ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKFWInstance *)NULL;
  }

  fwInstance = nss_ZNEW(arena, NSSCKFWInstance);
  if( (NSSCKFWInstance *)NULL == fwInstance ) {
    goto nomem;
  }

  fwInstance->arena = arena;
  fwInstance->mdInstance = mdInstance;

  fwInstance->LockingState = LockingState;
  if( (CK_C_INITIALIZE_ARGS_PTR)NULL != pInitArgs ) {
    fwInstance->initArgs = *pInitArgs;
    fwInstance->pInitArgs = &fwInstance->initArgs;
    if( pInitArgs->flags & CKF_LIBRARY_CANT_CREATE_OS_THREADS ) {
      fwInstance->mayCreatePthreads = CK_FALSE;
    } else {
      fwInstance->mayCreatePthreads = CK_TRUE;
    }
    fwInstance->configurationData = (NSSUTF8 *)(pInitArgs->pReserved);
  } else {
    fwInstance->mayCreatePthreads = CK_TRUE;
  }

  fwInstance->mutex = nssCKFWMutex_Create(pInitArgs, LockingState, arena,
                                          pError);
  if( (NSSCKFWMutex *)NULL == fwInstance->mutex ) {
    if( CKR_OK == *pError ) {
      *pError = CKR_GENERAL_ERROR;
    }
    goto loser;
  }

  if( (void *)NULL != (void *)mdInstance->Initialize ) {
    *pError = mdInstance->Initialize(mdInstance, fwInstance, fwInstance->configurationData);
    if( CKR_OK != *pError ) {
      goto loser;
    }

    called_Initialize = CK_TRUE;
  }

  if( (void *)NULL != (void *)mdInstance->ModuleHandlesSessionObjects ) {
    fwInstance->moduleHandlesSessionObjects = 
      mdInstance->ModuleHandlesSessionObjects(mdInstance, fwInstance);
  } else {
    fwInstance->moduleHandlesSessionObjects = CK_FALSE;
  }

  if( (void *)NULL == (void *)mdInstance->GetNSlots ) {
    /* That routine is required */
    *pError = CKR_GENERAL_ERROR;
    goto loser;
  }

  fwInstance->nSlots = mdInstance->GetNSlots(mdInstance, fwInstance, pError);
  if( (CK_ULONG)0 == fwInstance->nSlots ) {
    if( CKR_OK == *pError ) {
      /* Zero is not a legitimate answer */
      *pError = CKR_GENERAL_ERROR;
    }
    goto loser;
  }

  fwInstance->fwSlotList = nss_ZNEWARRAY(arena, NSSCKFWSlot *, fwInstance->nSlots);
  if( (NSSCKFWSlot **)NULL == fwInstance->fwSlotList ) {
    goto nomem;
  }

  fwInstance->mdSlotList = nss_ZNEWARRAY(arena, NSSCKMDSlot *, fwInstance->nSlots);
  if( (NSSCKMDSlot **)NULL == fwInstance->mdSlotList ) {
    goto nomem;
  }

  fwInstance->sessionHandleHash = nssCKFWHash_Create(fwInstance, 
    fwInstance->arena, pError);
  if( (nssCKFWHash *)NULL == fwInstance->sessionHandleHash ) {
    goto loser;
  }

  fwInstance->objectHandleHash = nssCKFWHash_Create(fwInstance,
    fwInstance->arena, pError);
  if( (nssCKFWHash *)NULL == fwInstance->objectHandleHash ) {
    goto loser;
  }

  if( (void *)NULL == (void *)mdInstance->GetSlots ) {
    /* That routine is required */
    *pError = CKR_GENERAL_ERROR;
    goto loser;
  }

  *pError = mdInstance->GetSlots(mdInstance, fwInstance, fwInstance->mdSlotList);
  if( CKR_OK != *pError ) {
    goto loser;
  }

  for( i = 0; i < fwInstance->nSlots; i++ ) {
    NSSCKMDSlot *mdSlot = fwInstance->mdSlotList[i];

    if( (NSSCKMDSlot *)NULL == mdSlot ) {
      *pError = CKR_GENERAL_ERROR;
      goto loser;
    }

    fwInstance->fwSlotList[i] = nssCKFWSlot_Create(fwInstance, mdSlot, i, pError);
    if( CKR_OK != *pError ) {
      CK_ULONG j;

      for( j = 0; j < i; j++ ) {
        (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[j]);
      }

      for( j = i; j < fwInstance->nSlots; j++ ) {
        NSSCKMDSlot *mds = fwInstance->mdSlotList[j];
        if( (void *)NULL != (void *)mds->Destroy ) {
          mds->Destroy(mds, (NSSCKFWSlot *)NULL, mdInstance, fwInstance);
        }
      }

      goto loser;
    }
  }

#ifdef DEBUG
  *pError = instance_add_pointer(fwInstance);
  if( CKR_OK != *pError ) {
    for( i = 0; i < fwInstance->nSlots; i++ ) {
      (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]);
    }
    
    goto loser;
  }
#endif /* DEBUG */

  *pError = CKR_OK;
  return fwInstance;

 nomem:
  *pError = CKR_HOST_MEMORY;
  /*FALLTHROUGH*/
 loser:

  if( CK_TRUE == called_Initialize ) {
    if( (void *)NULL != (void *)mdInstance->Finalize ) {
      mdInstance->Finalize(mdInstance, fwInstance);
    }
  }

  if (arena) {
    (void)NSSArena_Destroy(arena);
  }
  return (NSSCKFWInstance *)NULL;
}
NSS_IMPLEMENT NSSCKFWMutex* nssCKFWInstance_CreateMutex ( NSSCKFWInstance *  fwInstance,
NSSArena *  arena,
CK_RV pError 
)

Definition at line 494 of file instance.c.

{
  NSSCKFWMutex *mutex;

#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (NSSCKFWMutex *)NULL;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (NSSCKFWMutex *)NULL;
  }
#endif /* NSSDEBUG */

  mutex = nssCKFWMutex_Create(fwInstance->pInitArgs, fwInstance->LockingState,
                              arena, pError);
  if( (NSSCKFWMutex *)NULL == mutex ) {
    if( CKR_OK == *pError ) {
      *pError = CKR_GENERAL_ERROR;
    }

    return (NSSCKFWMutex *)NULL;
  }

  return mutex;
}
NSS_IMPLEMENT NSSCKFWMutex* NSSCKFWInstance_CreateMutex ( NSSCKFWInstance *  fwInstance,
NSSArena *  arena,
CK_RV pError 
)

Definition at line 1310 of file instance.c.

{
#ifdef DEBUG
  if( (CK_RV *)NULL == pError ) {
    return (NSSCKFWMutex *)NULL;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (NSSCKFWMutex *)NULL;
  }
#endif /* DEBUG */

  return nssCKFWInstance_CreateMutex(fwInstance, arena, pError);
}

Here is the caller graph for this function:

NSS_IMPLEMENT CK_OBJECT_HANDLE nssCKFWInstance_CreateObjectHandle ( NSSCKFWInstance *  fwInstance,
NSSCKFWObject *  fwObject,
CK_RV pError 
)

Definition at line 713 of file instance.c.

{
  CK_OBJECT_HANDLE hObject;

#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (CK_OBJECT_HANDLE)0;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (CK_OBJECT_HANDLE)0;
  }
#endif /* NSSDEBUG */

  *pError = nssCKFWMutex_Lock(fwInstance->mutex);
  if( CKR_OK != *pError ) {
    return (CK_OBJECT_HANDLE)0;
  }

  hObject = ++(fwInstance->lastObjectHandle);

  *pError = nssCKFWObject_SetHandle(fwObject, hObject);
  if( CKR_OK != *pError ) {
    hObject = (CK_OBJECT_HANDLE)0;
    goto done;
  }

  *pError = nssCKFWHash_Add(fwInstance->objectHandleHash, 
              (const void *)hObject, (const void *)fwObject);
  if( CKR_OK != *pError ) {
    hObject = (CK_OBJECT_HANDLE)0;
    goto done;
  }

 done:
  (void)nssCKFWMutex_Unlock(fwInstance->mutex);
  return hObject;
}
NSS_IMPLEMENT CK_SESSION_HANDLE nssCKFWInstance_CreateSessionHandle ( NSSCKFWInstance *  fwInstance,
NSSCKFWSession *  fwSession,
CK_RV pError 
)

Definition at line 570 of file instance.c.

{
  CK_SESSION_HANDLE hSession;

#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (CK_SESSION_HANDLE)0;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (CK_SESSION_HANDLE)0;
  }
#endif /* NSSDEBUG */

  *pError = nssCKFWMutex_Lock(fwInstance->mutex);
  if( CKR_OK != *pError ) {
    return (CK_SESSION_HANDLE)0;
  }

  hSession = ++(fwInstance->lastSessionHandle);

  /* Alan would say I should unlock for this call. */
  
  *pError = nssCKFWSession_SetHandle(fwSession, hSession);
  if( CKR_OK != *pError ) {
    goto done;
  }

  *pError = nssCKFWHash_Add(fwInstance->sessionHandleHash, 
              (const void *)hSession, (const void *)fwSession);
  if( CKR_OK != *pError ) {
    hSession = (CK_SESSION_HANDLE)0;
    goto done;
  }

 done:
  nssCKFWMutex_Unlock(fwInstance->mutex);
  return hSession;
}
NSS_IMPLEMENT CK_RV nssCKFWInstance_Destroy ( NSSCKFWInstance *  fwInstance)

Definition at line 382 of file instance.c.

{
#ifdef NSSDEBUG
  CK_RV error = CKR_OK;
#endif /* NSSDEBUG */
  CK_ULONG i;

#ifdef NSSDEBUG
  error = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != error ) {
    return error;
  }
#endif /* NSSDEBUG */

  nssCKFWMutex_Destroy(fwInstance->mutex);

  for( i = 0; i < fwInstance->nSlots; i++ ) {
    (void)nssCKFWSlot_Destroy(fwInstance->fwSlotList[i]);
  }

  if( (void *)NULL != (void *)fwInstance->mdInstance->Finalize ) {
    fwInstance->mdInstance->Finalize(fwInstance->mdInstance, fwInstance);
  }

  if (fwInstance->sessionHandleHash) {
     nssCKFWHash_Destroy(fwInstance->sessionHandleHash);
  }

  if (fwInstance->objectHandleHash) {
     nssCKFWHash_Destroy(fwInstance->objectHandleHash);
  }

#ifdef DEBUG
  (void)instance_remove_pointer(fwInstance);
#endif /* DEBUG */

  (void)NSSArena_Destroy(fwInstance->arena);
  return CKR_OK;
}
NSS_IMPLEMENT void nssCKFWInstance_DestroyObjectHandle ( NSSCKFWInstance *  fwInstance,
CK_OBJECT_HANDLE  hObject 
)

Definition at line 840 of file instance.c.

{
  NSSCKFWObject *fwObject;

#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return;
  }
#endif /* NSSDEBUG */

  if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
    return;
  }

  fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
                fwInstance->objectHandleHash, (const void *)hObject);
  /* Assert(hObject = nssCKFWObject_GetHandle(fwObject)) */
  nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject);
  (void)nssCKFWObject_SetHandle(fwObject, (CK_SESSION_HANDLE)0);

  (void)nssCKFWMutex_Unlock(fwInstance->mutex);
  return;
}
NSS_IMPLEMENT void nssCKFWInstance_DestroySessionHandle ( NSSCKFWInstance *  fwInstance,
CK_SESSION_HANDLE  hSession 
)

Definition at line 654 of file instance.c.

{
  NSSCKFWSession *fwSession;

#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return;
  }
#endif /* NSSDEBUG */

  if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
    return;
  }

  fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup(
                fwInstance->sessionHandleHash, (const void *)hSession);

  nssCKFWHash_Remove(fwInstance->sessionHandleHash, (const void *)hSession);
  nssCKFWSession_SetHandle(fwSession, (CK_SESSION_HANDLE)0);

  (void)nssCKFWMutex_Unlock(fwInstance->mutex);

  return;
}
NSS_IMPLEMENT CK_OBJECT_HANDLE nssCKFWInstance_FindObjectHandle ( NSSCKFWInstance *  fwInstance,
NSSCKFWObject *  fwObject 
)

Definition at line 873 of file instance.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (CK_OBJECT_HANDLE)0;
  }

  if( CKR_OK != nssCKFWObject_verifyPointer(fwObject) ) {
    return (CK_OBJECT_HANDLE)0;
  }
#endif /* NSSDEBUG */
  
  return nssCKFWObject_GetHandle(fwObject);
}
NSS_IMPLEMENT CK_SESSION_HANDLE nssCKFWInstance_FindSessionHandle ( NSSCKFWInstance *  fwInstance,
NSSCKFWSession *  fwSession 
)

Definition at line 688 of file instance.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (CK_SESSION_HANDLE)0;
  }

  if( CKR_OK != nssCKFWSession_verifyPointer(fwSession) ) {
    return (CK_SESSION_HANDLE)0;
  }
#endif /* NSSDEBUG */

  return nssCKFWSession_GetHandle(fwSession);
  /* look it up and assert? */
}
NSS_IMPLEMENT NSSArena* nssCKFWInstance_GetArena ( NSSCKFWInstance *  fwInstance,
CK_RV pError 
)

Definition at line 449 of file instance.c.

{
#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (NSSArena *)NULL;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (NSSArena *)NULL;
  }
#endif /* NSSDEBUG */

  *pError = CKR_OK;
  return fwInstance->arena;
}
NSS_IMPLEMENT NSSArena* NSSCKFWInstance_GetArena ( NSSCKFWInstance *  fwInstance,
CK_RV pError 
)

Definition at line 1266 of file instance.c.

{
#ifdef DEBUG
  if( (CK_RV *)NULL == pError ) {
    return (NSSArena *)NULL;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (NSSArena *)NULL;
  }
#endif /* DEBUG */

  return nssCKFWInstance_GetArena(fwInstance, pError);
}

Here is the caller graph for this function:

NSS_IMPLEMENT NSSUTF8* nssCKFWInstance_GetConfigurationData ( NSSCKFWInstance *  fwInstance)

Definition at line 532 of file instance.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (NSSUTF8 *)NULL;
  }
#endif /* NSSDEBUG */

  return fwInstance->configurationData;
}
NSS_IMPLEMENT NSSUTF8* NSSCKFWInstance_GetConfigurationData ( NSSCKFWInstance *  fwInstance)

Definition at line 1336 of file instance.c.

{
#ifdef DEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (NSSUTF8 *)NULL;
  }
#endif /* DEBUG */

  return nssCKFWInstance_GetConfigurationData(fwInstance);
}
NSS_IMPLEMENT CK_VERSION nssCKFWInstance_GetCryptokiVersion ( NSSCKFWInstance *  fwInstance)

Definition at line 923 of file instance.c.

{
  CK_VERSION rv;

#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    rv.major = rv.minor = 0;
    return rv;
  }
#endif /* NSSDEBUG */

  if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
    rv.major = rv.minor = 0;
    return rv;
  }

  if( (0 != fwInstance->cryptokiVersion.major) ||
      (0 != fwInstance->cryptokiVersion.minor) ) {
    rv = fwInstance->cryptokiVersion;
    goto done;
  }

  if( (void *)NULL != (void *)fwInstance->mdInstance->GetCryptokiVersion ) {
    fwInstance->cryptokiVersion = fwInstance->mdInstance->GetCryptokiVersion(
      fwInstance->mdInstance, fwInstance);
  } else {
    fwInstance->cryptokiVersion.major = 2;
    fwInstance->cryptokiVersion.minor = 1;
  }

  rv = fwInstance->cryptokiVersion;

 done:
  (void)nssCKFWMutex_Unlock(fwInstance->mutex);
  return rv;
}
NSS_IMPLEMENT CK_ULONG nssCKFWInstance_GetFlags ( NSSCKFWInstance *  fwInstance)

Definition at line 1017 of file instance.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (CK_ULONG)0;
  }
#endif /* NSSDEBUG */

  /* No "instance flags" are yet defined by Cryptoki. */
  return (CK_ULONG)0;
}
CK_C_INITIALIZE_ARGS_PTR nssCKFWInstance_GetInitArgs ( NSSCKFWInstance *  fwInstance)

Definition at line 551 of file instance.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (CK_C_INITIALIZE_ARGS_PTR)NULL;
  }
#endif /* NSSDEBUG */

    return fwInstance->pInitArgs;
}

Definition at line 1355 of file instance.c.

{
#ifdef DEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (CK_C_INITIALIZE_ARGS_PTR)NULL;
  }
#endif /* DEBUG */

  return nssCKFWInstance_GetInitArgs(fwInstance);
}
NSS_IMPLEMENT CK_RV nssCKFWInstance_GetLibraryDescription ( NSSCKFWInstance *  fwInstance,
CK_CHAR  libraryDescription[32] 
)

Definition at line 1037 of file instance.c.

{
  CK_RV error = CKR_OK;

#ifdef NSSDEBUG
  if( (CK_CHAR_PTR)NULL == libraryDescription ) {
    return CKR_ARGUMENTS_BAD;
  }

  error = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != error ) {
    return error;
  }
#endif /* NSSDEBUG */

  error = nssCKFWMutex_Lock(fwInstance->mutex);
  if( CKR_OK != error ) {
    return error;
  }

  if( (NSSUTF8 *)NULL == fwInstance->libraryDescription ) {
    if( (void *)NULL != (void *)fwInstance->mdInstance->GetLibraryDescription ) {
      fwInstance->libraryDescription = fwInstance->mdInstance->GetLibraryDescription(
        fwInstance->mdInstance, fwInstance, &error);
      if( ((NSSUTF8 *)NULL == fwInstance->libraryDescription) && (CKR_OK != error) ) {
        goto done;
      }
    } else {
      fwInstance->libraryDescription = (NSSUTF8 *) "";
    }
  }

  (void)nssUTF8_CopyIntoFixedBuffer(fwInstance->libraryDescription, (char *)libraryDescription, 32, ' ');
  error = CKR_OK;

 done:
  (void)nssCKFWMutex_Unlock(fwInstance->mutex);
  return error;
}
NSS_IMPLEMENT CK_VERSION nssCKFWInstance_GetLibraryVersion ( NSSCKFWInstance *  fwInstance)

Definition at line 1086 of file instance.c.

{
  CK_VERSION rv;

#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    rv.major = rv.minor = 0;
    return rv;
  }
#endif /* NSSDEBUG */

  if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
    rv.major = rv.minor = 0;
    return rv;
  }

  if( (0 != fwInstance->libraryVersion.major) ||
      (0 != fwInstance->libraryVersion.minor) ) {
    rv = fwInstance->libraryVersion;
    goto done;
  }

  if( (void *)NULL != (void *)fwInstance->mdInstance->GetLibraryVersion ) {
    fwInstance->libraryVersion = fwInstance->mdInstance->GetLibraryVersion(
      fwInstance->mdInstance, fwInstance);
  } else {
    fwInstance->libraryVersion.major = 0;
    fwInstance->libraryVersion.minor = 3;
  }

  rv = fwInstance->libraryVersion;
 done:
  (void)nssCKFWMutex_Unlock(fwInstance->mutex);
  return rv;
}
NSS_IMPLEMENT CK_RV nssCKFWInstance_GetManufacturerID ( NSSCKFWInstance *  fwInstance,
CK_CHAR  manufacturerID[32] 
)

Definition at line 968 of file instance.c.

{
  CK_RV error = CKR_OK;

#ifdef NSSDEBUG
  if( (CK_CHAR_PTR)NULL == manufacturerID ) {
    return CKR_ARGUMENTS_BAD;
  }

  error = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != error ) {
    return error;
  }
#endif /* NSSDEBUG */

  error = nssCKFWMutex_Lock(fwInstance->mutex);
  if( CKR_OK != error ) {
    return error;
  }

  if( (NSSUTF8 *)NULL == fwInstance->manufacturerID ) {
    if( (void *)NULL != (void *)fwInstance->mdInstance->GetManufacturerID ) {
      fwInstance->manufacturerID = fwInstance->mdInstance->GetManufacturerID(
        fwInstance->mdInstance, fwInstance, &error);
      if( ((NSSUTF8 *)NULL == fwInstance->manufacturerID) && (CKR_OK != error) ) {
        goto done;
      }
    } else {
      fwInstance->manufacturerID = (NSSUTF8 *) "";
    }
  }

  (void)nssUTF8_CopyIntoFixedBuffer(fwInstance->manufacturerID, (char *)manufacturerID, 32, ' ');
  error = CKR_OK;

 done:
  (void)nssCKFWMutex_Unlock(fwInstance->mutex);
  return error;
}
NSS_IMPLEMENT NSSCKMDInstance* nssCKFWInstance_GetMDInstance ( NSSCKFWInstance *  fwInstance)

Definition at line 430 of file instance.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (NSSCKMDInstance *)NULL;
  }
#endif /* NSSDEBUG */

  return fwInstance->mdInstance;
}
NSS_IMPLEMENT NSSCKMDInstance* NSSCKFWInstance_GetMDInstance ( NSSCKFWInstance *  fwInstance)

Definition at line 1247 of file instance.c.

{
#ifdef DEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (NSSCKMDInstance *)NULL;
  }
#endif /* DEBUG */

  return nssCKFWInstance_GetMDInstance(fwInstance);
}

Definition at line 1130 of file instance.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return CK_FALSE;
  }
#endif /* NSSDEBUG */

  return fwInstance->moduleHandlesSessionObjects;
}
NSS_IMPLEMENT CK_ULONG nssCKFWInstance_GetNSlots ( NSSCKFWInstance *  fwInstance,
CK_RV pError 
)

Definition at line 897 of file instance.c.

{
#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (CK_ULONG)0;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (CK_ULONG)0;
  }
#endif /* NSSDEBUG */

  *pError = CKR_OK;
  return fwInstance->nSlots;
}  
NSS_IMPLEMENT NSSCKFWSlot** nssCKFWInstance_GetSlots ( NSSCKFWInstance *  fwInstance,
CK_RV pError 
)

Definition at line 1149 of file instance.c.

{
#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (NSSCKFWSlot **)NULL;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (NSSCKFWSlot **)NULL;
  }
#endif /* NSSDEBUG */

  return fwInstance->fwSlotList;
}
NSS_IMPLEMENT CK_BBOOL nssCKFWInstance_MayCreatePthreads ( NSSCKFWInstance *  fwInstance)

Definition at line 475 of file instance.c.

{
#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return CK_FALSE;
  }
#endif /* NSSDEBUG */

  return fwInstance->mayCreatePthreads;
}
NSS_IMPLEMENT CK_BBOOL NSSCKFWInstance_MayCreatePthreads ( NSSCKFWInstance *  fwInstance)

Definition at line 1291 of file instance.c.

{
#ifdef DEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return CK_FALSE;
  }
#endif /* DEBUG */

  return nssCKFWInstance_MayCreatePthreads(fwInstance);
}
NSS_IMPLEMENT CK_RV nssCKFWInstance_ReassignObjectHandle ( NSSCKFWInstance *  fwInstance,
CK_OBJECT_HANDLE  hObject,
NSSCKFWObject *  fwObject 
)

Definition at line 795 of file instance.c.

{
  CK_RV error = CKR_OK;
  NSSCKFWObject *oldObject;

#ifdef NSSDEBUG
  error = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != error ) {
    return error;
  }
#endif /* NSSDEBUG */

  error = nssCKFWMutex_Lock(fwInstance->mutex);
  if( CKR_OK != error ) {
    return error;
  }

  oldObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
                 fwInstance->objectHandleHash, (const void *)hObject);
  /* Assert(hObject == nssCKFWObject_GetHandle(oldObject) */
  (void)nssCKFWObject_SetHandle(oldObject, (CK_SESSION_HANDLE)0);
  nssCKFWHash_Remove(fwInstance->objectHandleHash, (const void *)hObject);

  error = nssCKFWObject_SetHandle(fwObject, hObject);
  if( CKR_OK != error ) {
    goto done;
  }
  error = nssCKFWHash_Add(fwInstance->objectHandleHash, 
            (const void *)hObject, (const void *)fwObject);

 done:
  (void)nssCKFWMutex_Unlock(fwInstance->mutex);
  return error;
}
NSS_IMPLEMENT NSSCKFWObject* nssCKFWInstance_ResolveObjectHandle ( NSSCKFWInstance *  fwInstance,
CK_OBJECT_HANDLE  hObject 
)

Definition at line 763 of file instance.c.

{
  NSSCKFWObject *fwObject;

#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (NSSCKFWObject *)NULL;
  }
#endif /* NSSDEBUG */

  if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
    return (NSSCKFWObject *)NULL;
  }

  fwObject = (NSSCKFWObject *)nssCKFWHash_Lookup(
                fwInstance->objectHandleHash, (const void *)hObject);

  /* Assert(hObject == nssCKFWObject_GetHandle(fwObject)) */

  (void)nssCKFWMutex_Unlock(fwInstance->mutex);
  return fwObject;
}
NSS_IMPLEMENT NSSCKFWSession* nssCKFWInstance_ResolveSessionHandle ( NSSCKFWInstance *  fwInstance,
CK_SESSION_HANDLE  hSession 
)

Definition at line 621 of file instance.c.

{
  NSSCKFWSession *fwSession;

#ifdef NSSDEBUG
  if( CKR_OK != nssCKFWInstance_verifyPointer(fwInstance) ) {
    return (NSSCKFWSession *)NULL;
  }
#endif /* NSSDEBUG */

  if( CKR_OK != nssCKFWMutex_Lock(fwInstance->mutex) ) {
    return (NSSCKFWSession *)NULL;
  }

  fwSession = (NSSCKFWSession *)nssCKFWHash_Lookup(
                fwInstance->sessionHandleHash, (const void *)hSession);

  /* Assert(hSession == nssCKFWSession_GetHandle(fwSession)) */

  (void)nssCKFWMutex_Unlock(fwInstance->mutex);

  return fwSession;
}
NSS_IMPLEMENT NSSCKFWSlot* nssCKFWInstance_WaitForSlotEvent ( NSSCKFWInstance *  fwInstance,
CK_BBOOL  block,
CK_RV pError 
)

Definition at line 1174 of file instance.c.

{
  NSSCKFWSlot *fwSlot = (NSSCKFWSlot *)NULL;
  NSSCKMDSlot *mdSlot;
  CK_ULONG i, n;

#ifdef NSSDEBUG
  if( (CK_RV *)NULL == pError ) {
    return (NSSCKFWSlot *)NULL;
  }

  *pError = nssCKFWInstance_verifyPointer(fwInstance);
  if( CKR_OK != *pError ) {
    return (NSSCKFWSlot *)NULL;
  }

  switch( block ) {
  case CK_TRUE:
  case CK_FALSE:
    break;
  default:
    *pError = CKR_ARGUMENTS_BAD;
    return (NSSCKFWSlot *)NULL;
  }
#endif /* NSSDEBUG */

  if( (void *)NULL == (void *)fwInstance->mdInstance->WaitForSlotEvent ) {
    *pError = CKR_NO_EVENT;
    return (NSSCKFWSlot *)NULL;
  }

  mdSlot = fwInstance->mdInstance->WaitForSlotEvent(
    fwInstance->mdInstance,
    fwInstance,
    block,
    pError
  );

  if( (NSSCKMDSlot *)NULL == mdSlot ) {
    return (NSSCKFWSlot *)NULL;
  }

  n = nssCKFWInstance_GetNSlots(fwInstance, pError);
  if( ((CK_ULONG)0 == n) && (CKR_OK != *pError) ) {
    return (NSSCKFWSlot *)NULL;
  }

  for( i = 0; i < n; i++ ) {
    if( fwInstance->mdSlotList[i] == mdSlot ) {
      fwSlot = fwInstance->fwSlotList[i];
      break;
    }
  }

  if( (NSSCKFWSlot *)NULL == fwSlot ) {
    /* Internal error */
    *pError = CKR_GENERAL_ERROR;
    return (NSSCKFWSlot *)NULL;
  }

  return fwSlot;
}