/// <summary> /// Obtains a list of slots in the system /// </summary> /// <param name="slotsType">Type of slots to be obtained</param> /// <returns>List of available slots</returns> public List <ISlot> GetSlotList(SlotsType slotsType) { if (this._disposed) { throw new ObjectDisposedException(this.GetType().FullName); } _logger.Debug("Pkcs11({0})::GetSlotList", _libraryPath); NativeULong slotCount = 0; CKR rv = _p11.C_GetSlotList((slotsType == SlotsType.WithTokenPresent), null, ref slotCount); if (rv != CKR.CKR_OK) { throw new Pkcs11Exception("C_GetSlotList", rv); } if (slotCount == 0) { return(new List <ISlot>()); } else { NativeULong[] slotList = new NativeULong[slotCount]; rv = _p11.C_GetSlotList((slotsType == SlotsType.WithTokenPresent), slotList, ref slotCount); if (rv != CKR.CKR_OK) { throw new Pkcs11Exception("C_GetSlotList", rv); } if (slotList.Length != ConvertUtils.UInt32ToInt32(slotCount)) { Array.Resize(ref slotList, ConvertUtils.UInt32ToInt32(slotCount)); } List <ISlot> list = new List <ISlot>(); foreach (NativeULong slot in slotList) { list.Add(_factories.SlotFactory.CreateSlot(_factories, _p11, slot)); } return(list); } }
/// <summary> /// Obtains a list of slots in the system /// </summary> /// <param name="slotsType">Type of slots to be obtained</param> /// <returns>List of available slots</returns> public List <Slot> GetSlotList(SlotsType slotsType) { if (this._disposed) { throw new ObjectDisposedException(this.GetType().FullName); } uint slotCount = 0; CKR rv = _p11.C_GetSlotList((slotsType == SlotsType.WithTokenPresent), null, ref slotCount); if (rv != CKR.CKR_OK) { throw new Pkcs11Exception("C_GetSlotList", rv); } if (slotCount == 0) { return(new List <Slot>()); } else { uint[] slotList = new uint[slotCount]; rv = _p11.C_GetSlotList((slotsType == SlotsType.WithTokenPresent), slotList, ref slotCount); if (rv != CKR.CKR_OK) { throw new Pkcs11Exception("C_GetSlotList", rv); } if (slotList.Length != slotCount) { Array.Resize(ref slotList, Convert.ToInt32(slotCount)); } List <Slot> list = new List <Slot>(); foreach (uint slot in slotList) { list.Add(new Slot(_p11, slot)); } return(list); } }