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

Replace bools in public API with enums #54

Merged
merged 9 commits into from
Jun 11, 2017
Merged

Replace bools in public API with enums #54

merged 9 commits into from
Jun 11, 2017

Conversation

jariq
Copy link
Member

@jariq jariq commented Jun 11, 2017

Since we are already breaking assembly reference compatibility in #52 I am also going to explore the possibility of making API more user friendly.

This PR replaces several most annoying occurrences of bool type in public APIs with enum types. I believe that code with enums is not only easier to write but most importantly it is much easier to read.

Five new enums have been introduced:

1 - Net.Pkcs11Interop.Common.AppType

Previous code that initializes unmanaged PKCS#11 library in multi-threaded applications:

Pkcs11 pkcs11 = new Pkcs11("pkcs11-mock-x64.dll", true);

Current code that initializes unmanaged PKCS#11 library in multi-threaded applications:

Pkcs11 pkcs11 = new Pkcs11("pkcs11-mock-x64.dll", AppType.MultiThreaded);

2 - Net.Pkcs11Interop.Common.InitType

Previous code that initializes unmanaged PKCS#11 library with function pointers acquired with a single call of C_GetFunctionList function:

Pkcs11 pkcs11 = new Pkcs11("pkcs11-mock-x64.dll", true, true);

Current code that initializes unmanaged PKCS#11 library with function pointers acquired with a single call of C_GetFunctionList function:

Pkcs11 pkcs11 = new Pkcs11("pkcs11-mock-x64.dll", AppType.MultiThreaded, InitType.WithFunctionList);

3 - Net.Pkcs11Interop.Common.SlotsType

Previous code that obtains list of slots with token present:

List<Slot> slots = pkcs11.GetSlotList(true);

Current code that obtains list of slots with token present:

List<Slot> slots = pkcs11.GetSlotList(SlotsType.WithTokenPresent);

4 - Net.Pkcs11Interop.Common.WaitType

Previous code that analyzes slot events in non-blocking mode:

pkcs11.WaitForSlotEvent(true, out bool eventOccured, out ulong slotId);

Current code that analyzes slot events in non-blocking mode:

pkcs11.WaitForSlotEvent(WaitType.NonBlocking, out bool eventOccured, out ulong slotId);

5 - Net.Pkcs11Interop.Common.SessionType

Previous code that opens new read-only session:

Session session = slot.OpenSession(true);

Current code that opens new read-only session:

Session session = slot.OpenSession(SessionType.ReadOnly);

@jariq jariq changed the title API breaking changes Replace bools in public API with enums Jun 11, 2017
@jariq jariq merged commit 6a07d4e into master Jun 11, 2017
@jariq jariq deleted the api-changes branch June 11, 2017 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant