Added utils files.
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
#include "utils.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
CK_BBOOL has_token(const ykcs11_slot_t *slot) {
|
||||||
|
|
||||||
|
return (slot->info.flags & CKF_TOKEN_PRESENT);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CK_BBOOL parse_readers(const CK_BYTE_PTR readers, const CK_ULONG len,
|
||||||
|
ykcs11_slot_t *slots, CK_ULONG_PTR n_slots, CK_ULONG_PTR n_with_token) {
|
||||||
|
|
||||||
|
CK_BYTE i;
|
||||||
|
CK_BYTE_PTR p;
|
||||||
|
CK_BYTE_PTR s;
|
||||||
|
CK_ULONG l;
|
||||||
|
vendor_t vendor;
|
||||||
|
|
||||||
|
*n_slots = 0;
|
||||||
|
*n_with_token = 0;
|
||||||
|
p = readers;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* According to pcsc-lite, the format of a reader name is:
|
||||||
|
* name [interface] (serial) index slot
|
||||||
|
* http://ludovicrousseau.blogspot.se/2010/05/what-is-in-pcsc-reader-name.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
if (readers[i] == '\0' && i != len - 1) {
|
||||||
|
slots[*n_slots].vid = get_vendor_id(p);
|
||||||
|
|
||||||
|
if (slots[*n_slots].vid == UNKNOWN) {
|
||||||
|
// Unknown slot, just save what info we have
|
||||||
|
memset(&slots[*n_slots].info, 0, sizeof(CK_SLOT_INFO));
|
||||||
|
memset(slots[*n_slots].info.slotDescription, ' ', sizeof(slots[*n_slots].info.slotDescription));
|
||||||
|
strncpy(slots[*n_slots].info.slotDescription, p, strlen(p));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vendor = get_vendor(slots[*n_slots].vid);
|
||||||
|
|
||||||
|
// Values must NOT be null terminated and ' ' padded
|
||||||
|
|
||||||
|
memset(slots[*n_slots].info.slotDescription, ' ', sizeof(slots[*n_slots].info.slotDescription));
|
||||||
|
s = vendor.get_slot_description();
|
||||||
|
l = strlen(s);
|
||||||
|
strncpy(slots[*n_slots].info.slotDescription, s, l);
|
||||||
|
|
||||||
|
memset(slots[*n_slots].info.manufacturerID, ' ', sizeof(slots[*n_slots].info.manufacturerID));
|
||||||
|
s = vendor.get_slot_manufacturer();
|
||||||
|
l = strlen(s);
|
||||||
|
strncpy(slots[*n_slots].info.manufacturerID, s, l);
|
||||||
|
|
||||||
|
slots[*n_slots].info.flags = vendor.get_slot_flags();
|
||||||
|
|
||||||
|
if (has_token(slots + *n_slots))
|
||||||
|
(*n_with_token)++;
|
||||||
|
}
|
||||||
|
(*n_slots)++;
|
||||||
|
p += i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef UTILS_H
|
||||||
|
#define UTILS_H
|
||||||
|
|
||||||
|
#include "pkcs11.h"
|
||||||
|
#include "vendors.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
vendor_id_t vid;
|
||||||
|
CK_SLOT_INFO info;
|
||||||
|
} ykcs11_slot_t; // TODO: move this
|
||||||
|
|
||||||
|
CK_BBOOL has_token(const ykcs11_slot_t *slot);
|
||||||
|
CK_BBOOL parse_readers(const CK_BYTE_PTR readers, const CK_ULONG len,
|
||||||
|
ykcs11_slot_t *slots, CK_ULONG_PTR n_slots, CK_ULONG_PTR n_with_token);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user