/// <summary> /// Initializes new instance of Slot class /// </summary> /// <param name="pkcs11">Low level PKCS#11 wrapper</param> /// <param name="slotId">PKCS#11 handle of slot</param> internal Slot(LowLevelAPI.Pkcs11 pkcs11, uint slotId) { if (pkcs11 == null) { throw new ArgumentNullException("pkcs11"); } _p11 = pkcs11; _slotId = slotId; }
/// <summary> /// Disposes object /// </summary> /// <param name="disposing">Flag indicating whether managed resources should be disposed</param> protected virtual void Dispose(bool disposing) { if (!this._disposed) { if (disposing) { // Dispose managed objects if (_p11 != null) { _p11.C_Finalize(IntPtr.Zero); _p11.Dispose(); _p11 = null; } } // Dispose unmanaged objects _disposed = true; } }
/// <summary> /// Loads and initializes PCKS#11 library /// </summary> /// <param name="libraryPath">Library name or path</param> /// <param name="useOsLocking">Flag indicating whether PKCS#11 library can use the native operation system threading model for locking. Should be set to true in all multithreaded applications.</param> public Pkcs11(string libraryPath, bool useOsLocking) { if (libraryPath == null) { throw new ArgumentNullException("libraryPath"); } _p11 = new LowLevelAPI.Pkcs11(libraryPath); LowLevelAPI.CK_C_INITIALIZE_ARGS initArgs = null; if (useOsLocking) { initArgs = new LowLevelAPI.CK_C_INITIALIZE_ARGS(); initArgs.Flags = CKF.CKF_OS_LOCKING_OK; } CKR rv = _p11.C_Initialize(initArgs); if ((rv != CKR.CKR_OK) && (rv != CKR.CKR_CRYPTOKI_ALREADY_INITIALIZED)) { throw new Pkcs11Exception("C_Initialize", rv); } }