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 (
TEST_PROVIDER,
TEST_PROVIDER,
FALSE,
PKCS11H_SLOTEVENT_METHOD_AUTO,
0,
FALSE
)) != CKR_OK
) {
fatal ("pkcs11h_addProvider failed", rv);
}
printf ("Terminating pkcs11-helper\n");
fatal ("pkcs11h_terminate failed", rv);
}
exit (0);
return 0;
}