/// <summary> /// Initializes session with specified handle /// </summary> /// <param name="factories">Factories to be used by Developer and Pkcs11Interop library</param> /// <param name="pkcs11Library">Low level PKCS#11 wrapper</param> /// <param name="sessionId">PKCS#11 handle of session</param> public ISession Create(Pkcs11InteropFactories factories, LowLevelPkcs11Library pkcs11Library, ulong sessionId) { LowLevelAPI81.Pkcs11Library p11 = pkcs11Library as LowLevelAPI81.Pkcs11Library; if (p11 == null) { throw new ArgumentException("Incorrect type of low level PKCS#11 wrapper"); } return(new Session(factories, p11, sessionId)); }
/// <summary> /// Initializes new instance of Slot class /// </summary> /// <param name="factories">Factories to be used by Developer and Pkcs11Interop library</param> /// <param name="pkcs11Library">Low level PKCS#11 wrapper</param> /// <param name="slotId">PKCS#11 handle of slot</param> protected internal Slot(Pkcs11InteropFactories factories, LowLevelAPI81.Pkcs11Library pkcs11Library, ulong slotId) { _logger.Debug("Slot({0})::ctor", slotId); if (factories == null) { throw new ArgumentNullException("factories"); } if (pkcs11Library == null) { throw new ArgumentNullException("pkcs11Library"); } _factories = factories; _pkcs11Library = pkcs11Library; _slotId = ConvertUtils.UInt64FromUInt64(slotId); }
/// <summary> /// Disposes object /// </summary> /// <param name="disposing">Flag indicating whether managed resources should be disposed</param> protected virtual void Dispose(bool disposing) { _logger.Debug("Pkcs11Library({0})::Dispose2", _libraryPath); if (!this._disposed) { if (disposing) { // Dispose managed objects if (_pkcs11Library != null) { _pkcs11Library.C_Finalize(IntPtr.Zero); _logger.Info("Unloading PKCS#11 library {0}", _libraryPath); _pkcs11Library.Dispose(); _pkcs11Library = null; } } // Dispose unmanaged objects _disposed = true; } }
/// <summary> /// Loads and initializes PCKS#11 library /// </summary> /// <param name="factories">Factories to be used by Developer and Pkcs11Interop library</param> /// <param name="libraryPath">Library name or path</param> /// <param name="appType">Type of application that will be using PKCS#11 library</param> /// <param name="initType">Source of PKCS#11 function pointers</param> public Pkcs11Library(Pkcs11InteropFactories factories, string libraryPath, AppType appType, InitType initType) : this(factories, libraryPath) { _logger.Debug("Pkcs11Library({0})::ctor3", _libraryPath); try { _logger.Info("Loading PKCS#11 library {0}", _libraryPath); _pkcs11Library = new LowLevelAPI81.Pkcs11Library(_libraryPath, (initType == InitType.WithFunctionList)); Initialize(appType); } catch { if (_pkcs11Library != null) { _logger.Info("Unloading PKCS#11 library {0}", _libraryPath); _pkcs11Library.Dispose(); _pkcs11Library = null; } throw; } }