public void _01_BasicMechanismListAndInfoTest()
        {
            if (Platform.UnmanagedLongSize != 8 || Platform.StructPackingSize != 1)
                Assert.Inconclusive("Test cannot be executed on this platform");

            CKR rv = CKR.CKR_OK;
            
            using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath))
            {
                rv = pkcs11.C_Initialize(Settings.InitArgs81);
                if ((rv != CKR.CKR_OK) && (rv != CKR.CKR_CRYPTOKI_ALREADY_INITIALIZED))
                    Assert.Fail(rv.ToString());
                
                // Find first slot with token present
                ulong slotId = Helpers.GetUsableSlot(pkcs11);
                
                // Get number of supported mechanisms in first call
                ulong mechanismCount = 0;
                rv = pkcs11.C_GetMechanismList(slotId, null, ref mechanismCount);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
                
                Assert.IsTrue(mechanismCount > 0);
                
                // Allocate array for supported mechanisms
                CKM[] mechanismList = new CKM[mechanismCount];
                
                // Get supported mechanisms in second call
                rv = pkcs11.C_GetMechanismList(slotId, mechanismList, ref mechanismCount);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
                
                // Analyze first supported mechanism
                CK_MECHANISM_INFO mechanismInfo = new CK_MECHANISM_INFO();
                rv = pkcs11.C_GetMechanismInfo(slotId, mechanismList[0], ref mechanismInfo);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
                
                // Do something interesting with mechanism info
                
                rv = pkcs11.C_Finalize(IntPtr.Zero);
                if (rv != CKR.CKR_OK)
                    Assert.Fail(rv.ToString());
            }
        }
예제 #2
0
 /// <summary>
 /// Obtains information about a particular mechanism possibly supported by a token
 /// </summary>
 /// <param name="mechanism">Mechanism</param>
 /// <returns>Information about mechanism</returns>
 public MechanismInfo GetMechanismInfo(CKM mechanism)
 {
     CK_MECHANISM_INFO mechanismInfo = new CK_MECHANISM_INFO();
     CKR rv = _p11.C_GetMechanismInfo(_slotId, mechanism, ref mechanismInfo);
     if (rv != CKR.CKR_OK)
         throw new Pkcs11Exception("C_GetMechanismInfo", rv);
     
     return new MechanismInfo(mechanism, mechanismInfo);
 }
예제 #3
0
        /// <summary>
        /// Obtains information about a particular mechanism possibly supported by a token
        /// </summary>
        /// <param name="slotId">The ID of the token's slot</param>
        /// <param name="type">The type of mechanism</param>
        /// <param name="info">Structure that receives the mechanism information</param>
        /// <returns>CKR_CRYPTOKI_NOT_INITIALIZED, CKR_DEVICE_ERROR, CKR_DEVICE_MEMORY, CKR_DEVICE_REMOVED, CKR_FUNCTION_FAILED, CKR_GENERAL_ERROR, CKR_HOST_MEMORY, CKR_MECHANISM_INVALID, CKR_OK, CKR_SLOT_ID_INVALID, CKR_TOKEN_NOT_PRESENT, CKR_TOKEN_NOT_RECOGNIZED, CKR_ARGUMENTS_BAD</returns>
        public CKR C_GetMechanismInfo(ulong slotId, CKM type, ref CK_MECHANISM_INFO info)
        {
            if (this._disposed)
                throw new ObjectDisposedException(this.GetType().FullName);

            ulong rv = _delegates.C_GetMechanismInfo(slotId, Convert.ToUInt64(type), ref info);
            return (CKR)Convert.ToUInt32(rv);
        }
예제 #4
0
 internal static extern ulong C_GetMechanismInfo(ulong slotId, ulong type, ref CK_MECHANISM_INFO info);
예제 #5
0
 /// <summary>
 /// Converts low level CK_MECHANISM_INFO structure to high level MechanismInfo class
 /// </summary>
 /// <param name="mechanism">Mechanism</param>
 /// <param name="ck_mechanism_info">Low level CK_MECHANISM_INFO structure</param>
 internal MechanismInfo(CKM mechanism, CK_MECHANISM_INFO ck_mechanism_info)
 {
     _mechanism = mechanism;
     _minKeySize = ck_mechanism_info.MinKeySize;
     _maxKeySize = ck_mechanism_info.MaxKeySize;
     _mechanismFlags = new MechanismFlags(ck_mechanism_info.Flags);
 }
예제 #6
0
 internal static extern NativeULong C_GetMechanismInfo(NativeULong slotId, NativeULong type, ref CK_MECHANISM_INFO info);
예제 #7
0
 internal static extern CKR C_GetMechanismInfo(ulong slotId, ulong type, ref CK_MECHANISM_INFO info);