summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-12-01 19:28:09 +0000
committerStef Walter <stef@memberwebs.com>2008-12-01 19:28:09 +0000
commitf681943d31a66579781d59247c3f56384193d483 (patch)
tree8ab5179b4cbe6276494d717f5c44d73603425530
parentd1944835599808d5b13b470c84b762e64561b4ec (diff)
Make slot ids not start at zero.
-rw-r--r--ckcapi-token.c30
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