<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> <title>pkcs11-helper: test-basic.c</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.0 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div> <div class="contents"> <h1>test-basic.c</h1><p>The following example shows some basic usage of the library.</p> <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <stdio.h></span> <span class="preprocessor">#include <stdlib.h></span> <span class="preprocessor">#include "../../config.h"</span> <span class="preprocessor">#include <<a class="code" href="pkcs11h-core_8h.html" title="pkcs11-helper core.">pkcs11-helper-1.0/pkcs11h-core.h</a>></span> <span class="keyword">static</span> <span class="keywordtype">void</span> fatal (<span class="keyword">const</span> <span class="keywordtype">char</span> * <span class="keyword">const</span> m, CK_RV rv) { fprintf (stderr, <span class="stringliteral">"%s - %08lu - %s\n"</span>, m, rv, <a name="a0"></a><a class="code" href="group__pkcs11h__core.html#ga9aebf44a24ec0312cbf42a1024bbf290" title="Get message by return value.">pkcs11h_getMessage</a> (rv)); exit (1); } <span class="keyword">static</span> <span class="keywordtype">void</span> _pkcs11h_hooks_log ( IN <span class="keywordtype">void</span> * <span class="keyword">const</span> global_data, IN <span class="keywordtype">unsigned</span> flags, IN <span class="keyword">const</span> <span class="keywordtype">char</span> * <span class="keyword">const</span> format, IN va_list args ) { vfprintf (stdout, format, args); fprintf (stdout, <span class="stringliteral">"\n"</span>); fflush (stdout); } <span class="keywordtype">int</span> main () { CK_RV rv; printf (<span class="stringliteral">"Version: %08x\n"</span>, <a name="a1"></a><a class="code" href="group__pkcs11h__core.html#gaecea4287b494c1907b8c7e9dcde0d48b" title="Get version of library.">pkcs11h_getVersion</a> ()); printf (<span class="stringliteral">"Features: %08x\n"</span>, <a name="a2"></a><a class="code" href="group__pkcs11h__core.html#ga66cddd754ca08b5cf82881d22853d8bf" title="Get features of library.">pkcs11h_getFeatures</a> ()); printf (<span class="stringliteral">"Initializing pkcs11-helper\n"</span>); <span class="keywordflow">if</span> ((rv = <a name="a3"></a><a class="code" href="group__pkcs11h__core.html#gadf09a7c486742188b8ceedf84a5c5db6" title="Inititalize helper interface.">pkcs11h_initialize</a> ()) != CKR_OK) { fatal (<span class="stringliteral">"pkcs11h_initialize failed"</span>, rv); } printf (<span class="stringliteral">"Registering pkcs11-helper hooks\n"</span>); <span class="keywordflow">if</span> ((rv = <a name="a4"></a><a class="code" href="group__pkcs11h__core.html#gaf5dcc671471e326942f5ad9615840e8b" title="Set a log callback.">pkcs11h_setLogHook</a> (_pkcs11h_hooks_log, NULL)) != CKR_OK) { fatal (<span class="stringliteral">"pkcs11h_setLogHook failed"</span>, rv); } <a name="a5"></a><a class="code" href="group__pkcs11h__core.html#gad4b64d348be65a44012d7f2160cf27b2" title="Set current log level of the helper.">pkcs11h_setLogLevel</a> (TEST_LOG_LEVEL); printf (<span class="stringliteral">"Adding provider '%s'\n"</span>, TEST_PROVIDER); <span class="keywordflow">if</span> ( (rv = <a name="a6"></a><a class="code" href="group__pkcs11h__core.html#gafa48a26cc3c2662a87eef3eaa9523e23" title="Add a PKCS#11 provider.">pkcs11h_addProvider</a> ( TEST_PROVIDER, TEST_PROVIDER, FALSE, <a name="a7"></a><a class="code" href="group__PKCS11H__PRIVATEMODE__MASK.html#gafae49935ec998dabe7fd40b2ce7180dd">PKCS11H_PRIVATEMODE_MASK_AUTO</a>, PKCS11H_SLOTEVENT_METHOD_AUTO, 0, FALSE )) != CKR_OK ) { fatal (<span class="stringliteral">"pkcs11h_addProvider failed"</span>, rv); } printf (<span class="stringliteral">"Terminating pkcs11-helper\n"</span>); <span class="keywordflow">if</span> ((rv = <a name="a8"></a><a class="code" href="group__pkcs11h__core.html#gac8464931fa412eb69a118fe12c1778fe" title="Terminate helper interface.">pkcs11h_terminate</a> ()) != CKR_OK) { fatal (<span class="stringliteral">"pkcs11h_terminate failed"</span>, rv); } exit (0); <span class="keywordflow">return</span> 0; } </pre></div> </div> <hr> <table width="100%"><tr><td>pkcs11-helper, Copyright (C) Alon Bar-Lev <alon.barlev@gmail.com></td><td align="right"><a href="http://www.opensc-project.org"><img src="opensc-logo.gif" alt="OpenSC-Project.org Logo" border="0"/></a></td></tr></table>