diff options
-rw-r--r-- | ckcapi-token.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/ckcapi-token.c b/ckcapi-token.c index 906f181..87d918b 100644 --- a/ckcapi-token.c +++ b/ckcapi-token.c @@ -30,6 +30,8 @@ typedef struct _SlotInfo } SlotInfo; +#define SLOT_OFFSET 0x00001000 + static const SlotInfo slot_info[] = { { "My", "Personal Certificates", CKCAPI_SLOT_TRUSTED }, { "AddressBook", "Address Book Certificates", 0 }, @@ -40,39 +42,55 @@ static const SlotInfo slot_info[] = { { "AuthRoot", "Auth Root", 0 }, }; +#define SLOT_TO_OFFSET(slot) \ + ((slot) & ~(SLOT_OFFSET)) + +#define OFFSET_TO_SLOT(offset) \ + ((offset) | SLOT_OFFSET) + unsigned int ckcapi_token_get_count(void) { return sizeof(slot_info) / sizeof(slot_info[0]); } +ckcapi_token_get_slot_id(unsigned int offset) +{ + ASSERT(offset < ckcapi_token_get_count()); + return OFFSET_TO_SLOT(offset); +} + CK_BBOOL ckcapi_token_is_valid(CK_SLOT_ID slot) { - return slot >= 0 && slot < ckcapi_token_get_count(); + unsigned int offset = SLOT_TO_OFFSET(slot); + return offset >= 0 && offset < ckcapi_token_get_count(); } const char* ckcapi_token_get_display_name(CK_SLOT_ID slot) { + unsigned int offset = SLOT_TO_OFFSET(slot); ASSERT(ckcapi_token_is_valid(slot)); - ASSERT(slot_info[slot].display_name); - return slot_info[slot].display_name; + ASSERT(slot_info[offset].display_name); + return slot_info[offset].display_name; } const char* ckcapi_token_get_store_name(CK_SLOT_ID slot) { + unsigned int offset = SLOT_TO_OFFSET(slot); ASSERT(ckcapi_token_is_valid(slot)); - ASSERT(slot_info[slot].capi_store); - return slot_info[slot].capi_store; + ASSERT(slot_info[offset].capi_store); + return slot_info[offset].capi_store; } CK_ULONG ckcapi_token_get_flags(CK_SLOT_ID slot) { + unsigned int offset = SLOT_TO_OFFSET(slot); ASSERT(ckcapi_token_is_valid(slot)); - return slot_info[slot].slot_flags; + return slot_info[offset].slot_flags; } static void |