public C_GetMechanismInfo ( ulong slotId, CKM type, |
||
slotId | ulong | The ID of the token's slot |
type | CKM | The type of mechanism |
info | Structure that receives the mechanism information | |
return | CKR |
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()); } }