The following example shows some basic usage of the library.
#include <stdio.h>
#include <stdlib.h>
#include "../../config.h"
static
void
fatal (const char * const m, CK_RV rv) {
exit (1);
}
static
void
_pkcs11h_hooks_log (
IN void * const global_data,
IN unsigned flags,
IN const char * const format,
IN va_list args
) {
vfprintf (stdout, format, args);
fprintf (stdout, "\n");
fflush (stdout);
}
int main () {
CK_RV rv;
printf ("Initializing pkcs11-helper\n");
fatal ("pkcs11h_initialize failed", rv);
}
printf ("Registering pkcs11-helper hooks\n");
fatal ("pkcs11h_setLogHook failed", rv);
}
printf ("Adding provider '%s'\n", TEST_PROVIDER);
if (
"reference1",
TEST_PROVIDER,
TRUE,
0x55,
TRUE
)) != CKR_OK
) {
fatal ("pkcs11h_addProvider failed", rv);
}
printf ("Terminating pkcs11-helper\n");
fatal ("pkcs11h_terminate failed", rv);
}
exit (0);
return 0;
}
#define PKCS11H_PRIVATEMODE_MASK_DECRYPT
Definition pkcs11h-core.h:152
#define PKCS11H_SLOTEVENT_METHOD_POLL
Definition pkcs11h-core.h:167
const char * pkcs11h_getMessage(IN const CK_RV rv)
Get message by return value.
unsigned int pkcs11h_getFeatures(void)
Get features of library.
CK_RV pkcs11h_terminate(void)
Terminate helper interface.
void pkcs11h_setLogLevel(IN const unsigned flags)
Set current log level of the helper.
CK_RV pkcs11h_initialize(void)
Initialize helper interface.
unsigned int pkcs11h_getVersion(void)
Get version of library.
CK_RV pkcs11h_setLogHook(IN const pkcs11h_hook_log_t hook, IN void *const global_data)
Set a log callback.
CK_RV pkcs11h_addProvider(IN const char *const reference, IN const char *const provider_location, IN const PKCS11H_BOOL allow_protected_auth, IN const unsigned mask_private_mode, IN const unsigned slot_event_method, IN const unsigned slot_poll_interval, IN const PKCS11H_BOOL cert_is_private)
Register, configure and initialize a PKCS#11 provider.