Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic code generation #76

Merged
merged 16 commits into from
Mar 11, 2018
Merged
Prev Previous commit
Next Next commit
Regenerated tests for HighLevelAPIs
  • Loading branch information
jariq committed Feb 18, 2018
commit 34e0a24fbc6cbc34988f6004efef306128f3ad6a
13 changes: 11 additions & 2 deletions src/Pkcs11Interop/Pkcs11InteropTests/HighLevelAPI40/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* Jaroslav IMRICH <[email protected]>
*/

using System;
using System.Collections.Generic;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI40;
using NUnit.Framework;
using System;
using System.Collections.Generic;

namespace Net.Pkcs11Interop.Tests.HighLevelAPI40
{
Expand All @@ -32,6 +32,15 @@ namespace Net.Pkcs11Interop.Tests.HighLevelAPI40
/// </summary>
public static class Helpers
{
/// <summary>
/// Checks whether test can be executed on this platform
/// </summary>
public static void CheckPlatform()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
}

/// <summary>
/// Finds slot containing the token that matches criteria specified in Settings class
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class _01_InitializeTest
[Test()]
public void _01_BasicPkcs11DisposeTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

// Unmanaged PKCS#11 library is loaded by the constructor of Pkcs11 class.
// Every PKCS#11 library needs to be initialized with C_Initialize method
Expand All @@ -59,8 +58,7 @@ public void _01_BasicPkcs11DisposeTest()
[Test()]
public void _02_UsingPkcs11DisposeTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

// Pkcs11 class can be used in using statement which defines a scope
// at the end of which an object will be disposed.
Expand All @@ -76,8 +74,7 @@ public void _02_UsingPkcs11DisposeTest()
[Test()]
public void _03_SingleThreadedInitializeTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

// If an application will not be accessing PKCS#11 library from multiple threads
// simultaneously, it should specify "AppType.SingleThreaded" as a value of "appType" parameter.
Expand All @@ -93,8 +90,7 @@ public void _03_SingleThreadedInitializeTest()
[Test()]
public void _04_MultiThreadedInitializeTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

// If an application will be accessing PKCS#11 library from multiple threads
// simultaneously, it should specify "AppType.MultiThreaded" as a value of "appType" parameter.
Expand All @@ -111,15 +107,14 @@ public void _04_MultiThreadedInitializeTest()
[Test()]
public void _05_Pkcs11WithGetFunctionListTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

// Before an application can perform any cryptographic operations with Cryptoki library
// it has to obtain function pointers for all the Cryptoki API routines present in the library.
// This can be done either via C_GetFunctionList() function or via platform specific native
// function - GetProcAddress() on Windows and dlsym() on Unix.
// The most simple constructor of Net.Pkcs11Interop.HighLevelAPI40.Pkcs11 class uses
// C_GetFunctionList() approach but Pkcs11Interop also provides an alternative constructor
// The most simple constructor of Pkcs11 class uses C_GetFunctionList() approach
// but Pkcs11Interop also provides an alternative constructor
// that can specify which approach should be used.
using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType, InitType.WithFunctionList))
{
Expand All @@ -133,15 +128,14 @@ public void _05_Pkcs11WithGetFunctionListTest()
[Test()]
public void _06_Pkcs11WithoutGetFunctionListTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

// Before an application can perform any cryptographic operations with Cryptoki library
// it has to obtain function pointers for all the Cryptoki API routines present in the library.
// This can be done either via C_GetFunctionList() function or via platform specific native
// function - GetProcAddress() on Windows and dlsym() on Unix.
// The most simple constructor of Net.Pkcs11Interop.HighLevelAPI40.Pkcs11 class uses
// C_GetFunctionList() approach but Pkcs11Interop also provides an alternative constructor
// The most simple constructor of Pkcs11 class uses C_GetFunctionList() approach
// but Pkcs11Interop also provides an alternative constructor
// that can specify which approach should be used.
using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType, InitType.WithoutFunctionList))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI40;
using NUnit.Framework;

Expand All @@ -38,8 +37,7 @@ public class _02_GetInfoTest
[Test()]
public void _01_BasicGetInfoTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI40;
using NUnit.Framework;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.Tests.HighLevelAPI40
{
Expand All @@ -38,8 +39,7 @@ public class _03_SlotListInfoAndEventTest
[Test()]
public void _01_SlotListTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -58,8 +58,7 @@ public void _01_SlotListTest()
[Test()]
public void _02_BasicSlotListAndInfoTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -84,14 +83,13 @@ public void _02_BasicSlotListAndInfoTest()
[Test()]
public void _03_WaitForSlotEventTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
// Wait for a slot event
bool eventOccured = false;
uint slotId = 0;
NativeULong slotId = 0;
pkcs11.WaitForSlotEvent(WaitType.NonBlocking, out eventOccured, out slotId);
Assert.IsFalse(eventOccured);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI40;
using NUnit.Framework;

Expand All @@ -38,8 +37,7 @@ public class _04_TokenInfoTest
[Test()]
public void _01_BasicTokenInfoTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public class _05_MechanismListAndInfoTest
[Test()]
public void _01_BasicMechanismListAndInfoTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class _06_SessionTest
[Test()]
public void _01_BasicSessionTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -61,8 +60,7 @@ public void _01_BasicSessionTest()
[Test()]
public void _02_UsingSessionTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -84,8 +82,7 @@ public void _02_UsingSessionTest()
[Test()]
public void _03_CloseSessionViaSlotTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -108,8 +105,7 @@ public void _03_CloseSessionViaSlotTest()
[Test()]
public void _04_CloseAllSessionsTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -133,8 +129,7 @@ public void _04_CloseAllSessionsTest()
[Test()]
public void _05_ReadOnlySessionTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -155,8 +150,7 @@ public void _05_ReadOnlySessionTest()
[Test()]
public void _06_ReadWriteSessionTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -177,8 +171,7 @@ public void _06_ReadWriteSessionTest()
[Test()]
public void _07_SessionInfoTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class _07_OperationStateTest
[Test()]
public void _01_BasicOperationStateTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class _08_LoginTest
[Test()]
public void _01_NormalUserLoginTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -64,8 +63,7 @@ public void _01_NormalUserLoginTest()
[Test()]
public void _02_SecurityOfficerLoginTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class _09_InitTokenAndPinTest
[Test()]
public void _01_BasicInitTokenAndPinTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class _10_SetPinTest
[Test()]
public void _01_BasicSetPinTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class _11_SeedAndGenerateRandomTest
[Test()]
public void _01_SeedRandomTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -63,8 +62,7 @@ public void _01_SeedRandomTest()
[Test()]
public void _02_GenerateRandomTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* Jaroslav IMRICH <[email protected]>
*/

using System;
using System.IO;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI40;
Expand All @@ -39,8 +38,7 @@ public class _12_DigestTest
[Test()]
public void _01_DigestSinglePartTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -59,7 +57,7 @@ public void _01_DigestSinglePartTest()
byte[] digest = session.Digest(mechanism, sourceData);

// Do something interesting with digest value
Assert.IsTrue(Convert.ToBase64String(digest) == "e1AsOh9IyGCa4hLN+2Od7jlnP14=");
Assert.IsTrue(ConvertUtils.BytesToBase64String(digest) == "e1AsOh9IyGCa4hLN+2Od7jlnP14=");
}
}
}
Expand All @@ -70,8 +68,7 @@ public void _01_DigestSinglePartTest()
[Test()]
public void _02_DigestMultiPartTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand All @@ -95,7 +92,7 @@ public void _02_DigestMultiPartTest()
}

// Do something interesting with digest value
Assert.IsTrue(Convert.ToBase64String(digest) == "e1AsOh9IyGCa4hLN+2Od7jlnP14=");
Assert.IsTrue(ConvertUtils.BytesToBase64String(digest) == "e1AsOh9IyGCa4hLN+2Od7jlnP14=");
}
}
}
Expand All @@ -106,8 +103,7 @@ public void _02_DigestMultiPartTest()
[Test()]
public void _03_DigestKeyTest()
{
if (Platform.UnmanagedLongSize != 4 || Platform.StructPackingSize != 0)
Assert.Inconclusive("Test cannot be executed on this platform");
Helpers.CheckPlatform();

using (Pkcs11 pkcs11 = new Pkcs11(Settings.Pkcs11LibraryPath, Settings.AppType))
{
Expand Down
Loading