slot.c
来自「支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS」· C语言 代码 · 共 754 行 · 第 1/2 页
C
754 行
/* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is the Netscape security libraries. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1994-2000 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL"), in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your * version of this file only under the terms of the GPL and not to * allow others to use your version of this file under the MPL, * indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient * may use your version of this file under either the MPL or the * GPL. */#ifdef DEBUGstatic const char CVS_ID[] = "@(#) $RCSfile: slot.c,v $ $Revision: 1.3 $ $Date: 2000/09/06 22:23:57 $ $Name: NSS_3_1_1_RTM $";#endif /* DEBUG *//* * slot.c * * This file implements the NSSCKFWSlot type and methods. */#ifndef CK_T#include "ck.h"#endif /* CK_T *//* * NSSCKFWSlot * * -- create/destroy -- * nssCKFWSlot_Create * nssCKFWSlot_Destroy * * -- public accessors -- * NSSCKFWSlot_GetMDSlot * NSSCKFWSlot_GetFWInstance * NSSCKFWSlot_GetMDInstance * * -- implement public accessors -- * nssCKFWSlot_GetMDSlot * nssCKFWSlot_GetFWInstance * nssCKFWSlot_GetMDInstance * * -- private accessors -- * nssCKFWSlot_GetSlotID * nssCKFWSlot_ClearToken * * -- module fronts -- * nssCKFWSlot_GetSlotDescription * nssCKFWSlot_GetManufacturerID * nssCKFWSlot_GetTokenPresent * nssCKFWSlot_GetRemovableDevice * nssCKFWSlot_GetHardwareSlot * nssCKFWSlot_GetHardwareVersion * nssCKFWSlot_GetFirmwareVersion * nssCKFWSlot_InitToken * nssCKFWSlot_GetToken */struct NSSCKFWSlotStr { NSSCKFWMutex *mutex; NSSCKMDSlot *mdSlot; NSSCKFWInstance *fwInstance; NSSCKMDInstance *mdInstance; CK_SLOT_ID slotID; /* * Everything above is set at creation time, and then not modified. * The invariants the mutex protects are: * * 1) Each of the cached descriptions (versions, etc.) are in an * internally consistant state. * * 2) The fwToken points to the token currently in the slot, and * it is in a consistant state. * * Note that the calls accessing the cached descriptions will * call the NSSCKMDSlot methods with the mutex locked. Those * methods may then call the public NSSCKFWSlot routines. Those * public routines only access the constant data above, so there's * no problem. But be careful if you add to this object; mutexes * are in general not reentrant, so don't create deadlock situations. */ NSSUTF8 *slotDescription; NSSUTF8 *manufacturerID; CK_VERSION hardwareVersion; CK_VERSION firmwareVersion; NSSCKFWToken *fwToken;};#ifdef DEBUG/* * But first, the pointer-tracking stuff. * * NOTE: the pointer-tracking support in NSS/base currently relies * upon NSPR's CallOnce support. That, however, relies upon NSPR's * locking, which is tied into the runtime. We need a pointer-tracker * implementation that uses the locks supplied through C_Initialize. * That support, however, can be filled in later. So for now, I'll * just do this routines as no-ops. */static CK_RVslot_add_pointer( const NSSCKFWSlot *fwSlot){ return CKR_OK;}static CK_RVslot_remove_pointer( const NSSCKFWSlot *fwSlot){ return CKR_OK;}NSS_IMPLEMENT CK_RVnssCKFWSlot_verifyPointer( const NSSCKFWSlot *fwSlot){ return CKR_OK;}#endif /* DEBUG *//* * nssCKFWSlot_Create * */NSS_IMPLEMENT NSSCKFWSlot *nssCKFWSlot_Create( NSSCKFWInstance *fwInstance, NSSCKMDSlot *mdSlot, CK_SLOT_ID slotID, CK_RV *pError){ NSSCKFWSlot *fwSlot; NSSCKMDInstance *mdInstance; NSSArena *arena;#ifdef NSSDEBUG if( (CK_RV *)NULL == pError ) { return (NSSCKFWSlot *)NULL; } *pError = nssCKFWInstance_verifyPointer(fwInstance); if( CKR_OK != *pError ) { return (NSSCKFWSlot *)NULL; }#endif /* NSSDEBUG */ mdInstance = nssCKFWInstance_GetMDInstance(fwInstance); if( (NSSCKMDInstance *)NULL == mdInstance ) { *pError = CKR_GENERAL_ERROR; return (NSSCKFWSlot *)NULL; } arena = nssCKFWInstance_GetArena(fwInstance, pError); if( (NSSArena *)NULL == arena ) { if( CKR_OK == *pError ) { *pError = CKR_GENERAL_ERROR; } } fwSlot = nss_ZNEW(arena, NSSCKFWSlot); if( (NSSCKFWSlot *)NULL == fwSlot ) { *pError = CKR_HOST_MEMORY; return (NSSCKFWSlot *)NULL; } fwSlot->mdSlot = mdSlot; fwSlot->fwInstance = fwInstance; fwSlot->mdInstance = mdInstance; fwSlot->slotID = slotID; fwSlot->mutex = nssCKFWInstance_CreateMutex(fwInstance, arena, pError); if( (NSSCKFWMutex *)NULL == fwSlot->mutex ) { if( CKR_OK == *pError ) { *pError = CKR_GENERAL_ERROR; } (void)nss_ZFreeIf(fwSlot); return (NSSCKFWSlot *)NULL; } if( (void *)NULL != (void *)mdSlot->Initialize ) { *pError = CKR_OK; *pError = mdSlot->Initialize(mdSlot, fwSlot, mdInstance, fwInstance); if( CKR_OK != *pError ) { (void)nssCKFWMutex_Destroy(fwSlot->mutex); (void)nss_ZFreeIf(fwSlot); return (NSSCKFWSlot *)NULL; } }#ifdef DEBUG *pError = slot_add_pointer(fwSlot); if( CKR_OK != *pError ) { if( (void *)NULL != (void *)mdSlot->Destroy ) { mdSlot->Destroy(mdSlot, fwSlot, mdInstance, fwInstance); } (void)nssCKFWMutex_Destroy(fwSlot->mutex); (void)nss_ZFreeIf(fwSlot); return (NSSCKFWSlot *)NULL; }#endif /* DEBUG */ return fwSlot;}/* * nssCKFWSlot_Destroy * */NSS_IMPLEMENT CK_RVnssCKFWSlot_Destroy( NSSCKFWSlot *fwSlot){ CK_RV error = CKR_OK;#ifdef NSSDEBUG error = nssCKFWSlot_verifyPointer(fwSlot); if( CKR_OK != error ) { return error; }#endif /* NSSDEBUG */ (void)nssCKFWMutex_Destroy(fwSlot->mutex); if( (void *)NULL != (void *)fwSlot->mdSlot->Destroy ) { fwSlot->mdSlot->Destroy(fwSlot->mdSlot, fwSlot, fwSlot->mdInstance, fwSlot->fwInstance); }#ifdef DEBUG error = slot_remove_pointer(fwSlot);#endif /* DEBUG */ (void)nss_ZFreeIf(fwSlot); return error;}/* * nssCKFWSlot_GetMDSlot * */NSS_IMPLEMENT NSSCKMDSlot *nssCKFWSlot_GetMDSlot( NSSCKFWSlot *fwSlot){#ifdef NSSDEBUG if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { return (NSSCKMDSlot *)NULL; }#endif /* NSSDEBUG */ return fwSlot->mdSlot;}/* * nssCKFWSlot_GetFWInstance * */NSS_IMPLEMENT NSSCKFWInstance *nssCKFWSlot_GetFWInstance( NSSCKFWSlot *fwSlot){#ifdef NSSDEBUG if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { return (NSSCKFWInstance *)NULL; }#endif /* NSSDEBUG */ return fwSlot->fwInstance;}/* * nssCKFWSlot_GetMDInstance * */NSS_IMPLEMENT NSSCKMDInstance *nssCKFWSlot_GetMDInstance( NSSCKFWSlot *fwSlot){#ifdef NSSDEBUG if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { return (NSSCKMDInstance *)NULL; }#endif /* NSSDEBUG */ return fwSlot->mdInstance;}/* * nssCKFWSlot_GetSlotID * */NSS_IMPLEMENT CK_SLOT_IDnssCKFWSlot_GetSlotID( NSSCKFWSlot *fwSlot){#ifdef NSSDEBUG if( CKR_OK != nssCKFWSlot_verifyPointer(fwSlot) ) { return (CK_SLOT_ID)0; }#endif /* NSSDEBUG */ return fwSlot->slotID;}/* * nssCKFWSlot_GetSlotDescription * */NSS_IMPLEMENT CK_RVnssCKFWSlot_GetSlotDescription( NSSCKFWSlot *fwSlot, CK_CHAR slotDescription[64]){ CK_RV error = CKR_OK;#ifdef NSSDEBUG if( (CK_CHAR_PTR)NULL == slotDescription ) { return CKR_ARGUMENTS_BAD; } error = nssCKFWSlot_verifyPointer(fwSlot); if( CKR_OK != error ) { return error; }#endif /* NSSDEBUG */ error = nssCKFWMutex_Lock(fwSlot->mutex); if( CKR_OK != error ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?