/// <summary> /// Disposes object /// </summary> /// <param name="disposing">Flag indicating whether managed resources should be disposed</param> protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { // Dispose managed objects if (_slots != null) { for (int i = 0; i < _slots.Count; i++) { if (_slots[i] != null) { _slots[i].Dispose(); _slots[i] = null; } } } if (_storeContext != null) { _storeContext.Dispose(); _storeContext = null; } } // Dispose unmanaged objects _disposed = true; } }
/// <summary> /// Creates new instance of Pkcs11X509Store class. /// Also loads and initializes unmanaged PCKS#11 library. /// </summary> /// <param name="libraryPath">Name of or path to PKCS#11 library</param> /// <param name="pinProvider">Provider of PIN codes for PKCS#11 tokens and keys</param> public Pkcs11X509Store(string libraryPath, IPinProvider pinProvider) { if (string.IsNullOrEmpty(libraryPath)) { throw new ArgumentNullException(nameof(libraryPath)); } if (pinProvider == null) { throw new ArgumentNullException(nameof(pinProvider)); } _storeContext = this.GetStoreContext(libraryPath, pinProvider); _slots = this.GetSlots(); }
/// <summary> /// Creates new instance of Pkcs11Slot class /// </summary> /// <param name="slot">High level PKCS#11 slot</param> /// <param name="storeContext">Internal context for Pkcs11X509Store class</param> internal Pkcs11Slot(ISlot slot, Pkcs11X509StoreContext storeContext) { if (slot == null) { throw new ArgumentNullException(nameof(slot)); } if (storeContext == null) { throw new ArgumentNullException(nameof(storeContext)); } _slotContext = this.GetSlotContext(slot, storeContext); _token = this.GetToken(); }
/// <summary> /// Constructs internal context for Pkcs11Slot class /// </summary> /// <param name="slot">High level PKCS#11 slot</param> /// <param name="storeContext">Internal context for Pkcs11X509Store class</param> /// <returns>Internal context for Pkcs11Slot class</returns> private Pkcs11SlotContext GetSlotContext(ISlot slot, Pkcs11X509StoreContext storeContext) { var slotInfo = new Pkcs11SlotInfo(slot.GetSlotInfo()); return(new Pkcs11SlotContext(slot, slotInfo, storeContext)); }
/// <summary> /// Creates new instance of Pkcs11SlotContext class /// </summary> /// <param name="slot">High level PKCS#11 slot</param> /// <param name="slotInfo">Detailed information about PKCS#11 slot</param> /// <param name="storeContext">Internal context for Pkcs11X509Store class</param> internal Pkcs11SlotContext(ISlot slot, Pkcs11SlotInfo slotInfo, Pkcs11X509StoreContext storeContext) { _slot = slot ?? throw new ArgumentNullException(nameof(slot)); _slotInfo = slotInfo ?? throw new ArgumentNullException(nameof(slotInfo)); _storeContext = storeContext ?? throw new ArgumentNullException(nameof(storeContext)); }