public List <IRutokenSlot> GetRutokenSlotList(SlotsType slotsType) { List <ISlot> slots = GetSlotList(slotsType); if (slots == null) { return(null); } return(GetSlotList(slotsType).Select(slot => (IRutokenSlot)slot).ToList()); }
/// <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); } if (Platform.UnmanagedLongSize == 4) { List <Slot> slotList = new List <Slot>(); if (Platform.StructPackingSize == 0) { List <HighLevelAPI40.Slot> hlaSlotList = _p11_40.GetSlotList(slotsType); foreach (HighLevelAPI40.Slot hlaSlot in hlaSlotList) { slotList.Add(new Slot(hlaSlot)); } } else { List <HighLevelAPI41.Slot> hlaSlotList = _p11_41.GetSlotList(slotsType); foreach (HighLevelAPI41.Slot hlaSlot in hlaSlotList) { slotList.Add(new Slot(hlaSlot)); } } return(slotList); } else { List <Slot> slotList = new List <Slot>(); if (Platform.StructPackingSize == 0) { List <HighLevelAPI80.Slot> hlaSlotList = _p11_80.GetSlotList(slotsType); foreach (HighLevelAPI80.Slot hlaSlot in hlaSlotList) { slotList.Add(new Slot(hlaSlot)); } } else { List <HighLevelAPI81.Slot> hlaSlotList = _p11_81.GetSlotList(slotsType); foreach (HighLevelAPI81.Slot hlaSlot in hlaSlotList) { slotList.Add(new Slot(hlaSlot)); } } return(slotList); } }
/// <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.UInt64ToInt32(slotCount)) { Array.Resize(ref slotList, ConvertUtils.UInt64ToInt32(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 all PKCS#11 URI matching slots /// </summary> /// <param name="pkcs11Uri">PKCS#11 URI</param> /// <param name="pkcs11">High level PKCS#11 wrapper</param> /// <param name="slotsType">Type of slots to be obtained</param> /// <returns>List of slots matching PKCS#11 URI</returns> public static List <ISlot> GetMatchingSlotList(Pkcs11Uri pkcs11Uri, IPkcs11 pkcs11, SlotsType slotsType) { if (pkcs11Uri == null) { throw new ArgumentNullException("pkcs11Uri"); } if (pkcs11 == null) { throw new ArgumentNullException("pkcs11"); } List <ISlot> matchingSlots = new List <ISlot>(); ILibraryInfo libraryInfo = pkcs11.GetInfo(); if (!Matches(pkcs11Uri, libraryInfo)) { return(matchingSlots); } List <ISlot> slots = pkcs11.GetSlotList(SlotsType.WithOrWithoutTokenPresent); if ((slots == null) || (slots.Count == 0)) { return(matchingSlots); } foreach (ISlot slot in slots) { ISlotInfo slotInfo = slot.GetSlotInfo(); if (Matches(pkcs11Uri, slotInfo)) { if (slotInfo.SlotFlags.TokenPresent) { ITokenInfo tokenInfo = slot.GetTokenInfo(); if (Matches(pkcs11Uri, tokenInfo)) { matchingSlots.Add(slot); } } else { if (slotsType == SlotsType.WithOrWithoutTokenPresent && Pkcs11UriSharedUtils.Matches(pkcs11Uri, null, null, null, null)) { matchingSlots.Add(slot); } } } } return(matchingSlots); }