/// <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); } 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 <Slot>()); } 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 != NativeLongUtils.ConvertToInt32(slotCount)) { Array.Resize(ref slotList, NativeLongUtils.ConvertToInt32(slotCount)); } List <Slot> list = new List <Slot>(); foreach (NativeULong slot in slotList) { list.Add(new Slot(_p11, slot)); } return(list); } }
/// <summary> /// Obtains a list of slots in the system /// </summary> /// <param name="tokenPresent">Flag indicating whether the list obtained includes only those slots with a token present (true), or all slots (false)</param> /// <returns>List of available slots</returns> public List <Slot> GetSlotList(bool tokenPresent) { if (this._disposed) { throw new ObjectDisposedException(this.GetType().FullName); } uint slotCount = 0; CKR rv = _p11.C_GetSlotList(tokenPresent, 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(tokenPresent, 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); } }