/// <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 LowLevelAPI40.Pkcs11Library(_libraryPath, (initType == InitType.WithFunctionList)); Initialize(appType); } catch { if (_pkcs11Library != null) { _logger.Info("Unloading PKCS#11 library {0}", _libraryPath); _pkcs11Library.Dispose(); _pkcs11Library = null; } throw; } }