many new but completely untested methods

master
Marc Wäckerlin 15 years ago
parent cf07cb1707
commit f1cd9514f3
  1. 2
      configure.in
  2. 0
      doc/examples/cryptoki-demo.cxx
  3. 19
      doc/examples/makefile.am
  4. 2
      doc/examples/pcsc-demo.cxx
  5. 2
      doc/makefile.am
  6. 370
      src/cryptoki.hxx
  7. 4
      src/makefile.am

@ -13,7 +13,7 @@ AM_INIT_AUTOMAKE(x_packagename, x_major.x_minor.x_least, [marc@waeckerlin.org])
# files to create # files to create
AC_CONFIG_FILES(makefile AC_CONFIG_FILES(makefile
src/makefile test/makefile src/makefile test/makefile
doc/doxyfile doc/makefile) doc/doxyfile doc/examples/makefile doc/makefile)
# copy M4 to shell # copy M4 to shell
PACKAGENAME=x_packagename PACKAGENAME=x_packagename

@ -0,0 +1,19 @@
## @id $Id$
## 1 2 3 4 5 6 7 8
## 45678901234567890123456789012345678901234567890123456789012345678901234567890
noinst_PROGRAMS = pcsc-demo cryptoki-demo
AM_CXXFLAGS = -I${top_srcdir}/src \
-I/usr/include/PCSC \
-I/usr/include/opencryptoki
pcsc_demo_SOURCES = pcsc-demo.cxx
pcsc_demo_LDADD = -lpcsclite
cryptoki_demo_SOURCES = cryptoki-demo.cxx
cryptoki_demo_LDADD = -ldl -lcryptoki++
cryptoki_demo_LDFLAGS = -L${top_builddir}/src
MAINTAINERCLEANFILES = makefile.in

@ -1,5 +1,5 @@
//g++ -I ../svn -I /usr/include/PCSC test.cpp -lpcsclite -ggdb3 //g++ -I ../svn -I /usr/include/PCSC test.cpp -lpcsclite -ggdb3
#include "pcscpp/pcsc.hxx" #include <pcsc.hxx>
#include <iostream> #include <iostream>
int main(int, char const*const*const argv) try { int main(int, char const*const*const argv) try {

@ -5,6 +5,8 @@
## 1 2 3 4 5 6 7 8 ## 1 2 3 4 5 6 7 8
## 45678901234567890123456789012345678901234567890123456789012345678901234567890 ## 45678901234567890123456789012345678901234567890123456789012345678901234567890
SUBDIRS = examples
develdir = ${pkgdatadir}/doc develdir = ${pkgdatadir}/doc
devel_DATA = html/index.html devel_DATA = html/index.html

@ -366,12 +366,22 @@ namespace cryptoki {
@param exc wether exceptions should be thrown */ @param exc wether exceptions should be thrown */
Init(const std::string& library="onepin-opensc-pkcs11.so", bool exc=true); Init(const std::string& library="onepin-opensc-pkcs11.so", bool exc=true);
/*! @name C Like Error Handling
You are strongly recommended not to disable exception
handling. If you disable it, you must check after every
operation whether it was successful or not. These methods
provide all you need for that. */
//@{
/*! @return @c true if last cryptoki on this object call was successful */ /*! @return @c true if last cryptoki on this object call was successful */
operator bool(); operator bool();
/*! @return error text of last cryptoki call */ /*! @return error text of last cryptoki call */
std::string error(); std::string error();
//@}
Info info() { Info info() {
Info inf; Info inf;
CK_INFO cInf; CK_INFO cInf;
@ -397,8 +407,9 @@ namespace cryptoki {
class Slot { class Slot {
private: private:
friend class Session;
friend class Init; friend class Init;
friend class Session;
friend class Object;
Init* _init; Init* _init;
CK_SLOT_ID _slot; CK_SLOT_ID _slot;
@ -420,6 +431,14 @@ namespace cryptoki {
public: public:
/*! @name C Like Error Handling
You are strongly recommended not to disable exception
handling. If you disable it, you must check after every
operation whether it was successful or not. These methods
provide all you need for that. */
//@{
/*! @return @c true if last cryptoki on this object call was successful */ /*! @return @c true if last cryptoki on this object call was successful */
operator bool() { operator bool() {
return _res==CKR_OK; return _res==CKR_OK;
@ -430,6 +449,8 @@ namespace cryptoki {
return _init->error(_res); return _init->error(_res);
} }
//@}
MechanismInfo mechanismInfo(Mechanism mechanism) { MechanismInfo mechanismInfo(Mechanism mechanism) {
MechanismInfo info; MechanismInfo info;
//! calls @c C_GetMechanismInfo //! calls @c C_GetMechanismInfo
@ -502,20 +523,27 @@ namespace cryptoki {
return info; return info;
} }
/*! @todo Not implemented: std::string inittoken(std::string in) {
@code std::string res;
bool inittoken() { res.resize(in.size());
//! calls @c C_InitToken //! calls @c C_InitToken
return check(_init->_fn->C_InitToken(_slot, CK_CHAR_PTR, CK_ULONG, CK_CHAR_PTR), check(_init->_fn->C_InitToken
(_slot,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->()),
CRYPTOKI_FN_LOG("C_InitToken")); CRYPTOKI_FN_LOG("C_InitToken"));
return res;
} }
@endcode */
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool waitforslotevent() { class SlotEventListener {
public: virtual void slotEvent() = 0;
}
bool registerforslotevent(SlotEventListener&) {
//! calls @c C_WaitForSlotEvent //! calls @c C_WaitForSlotEvent
return check(_init->_fn->C_WaitForSlotEvent(CK_FLAGS, _slot_PTR, CK_VOID_PTR), return check(_init->_fn->C_WaitForSlotEvent(CK_FLAGS, &_slot, CK_VOID_PTR),
CRYPTOKI_FN_LOG("C_WaitForSlotEvent")); CRYPTOKI_FN_LOG("C_WaitForSlotEvent"));
} }
@endcode */ @endcode */
@ -526,6 +554,8 @@ namespace cryptoki {
class Session { class Session {
private: private:
friend class Object;
Slot& _slot; Slot& _slot;
CK_SESSION_HANDLE _session; CK_SESSION_HANDLE _session;
CK_RV _res; CK_RV _res;
@ -549,12 +579,10 @@ namespace cryptoki {
//! Opens a new session. //! Opens a new session.
/*! @param slot slot to open a session on */ /*! @param slot slot to open a session on */
Session(Slot& slot): _slot(slot), _session(0), _res(CKR_OK) { Session(Slot& slot): _slot(slot), _session(0), _res(CKR_OK) {
/*! @todo implement
//! calls @c C_OpenSession //! calls @c C_OpenSession
return check(_slot._init->_fn->C_OpenSession(_slot._slot, CK_FLAGS, CK_VOID_PTR, CK_NOTIFY, check(_slot._init->_fn->C_OpenSession(_slot._slot, 0, 0, 0, &_session),
&_session),
CRYPTOKI_FN_LOG("C_OpenSession")); CRYPTOKI_FN_LOG("C_OpenSession"));
*/ //! @todo pass parameter
} }
//! Closes actual session //! Closes actual session
@ -568,6 +596,14 @@ namespace cryptoki {
} }
} }
/*! @name C Like Error Handling
You are strongly recommended not to disable exception
handling. If you disable it, you must check after every
operation whether it was successful or not. These methods
provide all you need for that. */
//@{
/*! @return @c true if last cryptoki on this object call was successful */ /*! @return @c true if last cryptoki on this object call was successful */
operator bool() { operator bool() {
return _res==CKR_OK; return _res==CKR_OK;
@ -578,84 +614,118 @@ namespace cryptoki {
return _slot._init->error(_res); return _slot._init->error(_res);
} }
/*! @todo Not implemented: //@}
@code
void cancel() { /*! @name Low Level Cryptoki Functions
Direct access to the low level cryptoki API. Better use the
comfort methods. */
//@{
bool cancel() {
//! calls @c C_CancelFunction //! calls @c C_CancelFunction
return check(_slot._init->_fn->C_CancelFunction(_session), return check(_slot._init->_fn->C_CancelFunction(_session),
CRYPTOKI_FN_LOG("C_CancelFunction")); CRYPTOKI_FN_LOG("C_CancelFunction"));
} }
@endcode */
/*! @todo Not implemented: std::string decrypt(std::string in) {
@code std::string res;
bool decrypt() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_Decrypt //! calls @c C_Decrypt
return check(_slot._init->_fn->C_Decrypt(_session, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR, check(_slot._init->_fn->C_Decrypt
CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_Decrypt")); CRYPTOKI_FN_LOG("C_Decrypt"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: std::string decryptdigestupdate(std::string in) {
@code std::string res;
bool decryptdigestupdate() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DecryptDigestUpdate //! calls @c C_DecryptDigestUpdate
return check(_slot._init->_fn->C_DecryptDigestUpdate(_session, CK_BYTE_PTR, CK_ULONG, check(_slot._init->_fn->C_DecryptDigestUpdate
CK_BYTE_PTR, CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_DecryptDigestUpdate")); CRYPTOKI_FN_LOG("C_DecryptDigestUpdate"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: std::string decryptfinal(std::string in) {
@code std::string res;
bool decryptfinal() { // res.resize(in.size());
//! calls @c C_DecryptFinal // CK_ULONG size(res.size()); //! @todo check if size is ok
return check(_slot._init->_fn->C_DecryptFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR), // //! calls @c C_DecryptFinal
CRYPTOKI_FN_LOG("C_DecryptFinal")); // check(_slot._init->_fn->C_DecryptFinal
// (_session,
// (unsigned char*)in.begin().operator->(), in.size(),
// (unsigned char*)res.begin().operator->(), &size),
// CRYPTOKI_FN_LOG("C_DecryptFinal"));
// res.resize(size);
//! @todo check docu
return res;
} }
@endcode */
/*! @todo Not implemented: std::string decryptupdate(std::string in) {
@code std::string res;
bool decryptupdate() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DecryptUpdate //! calls @c C_DecryptUpdate
return check(_slot._init->_fn->C_DecryptUpdate(_session, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR, check(_slot._init->_fn->C_DecryptUpdate
CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_DecryptUpdate")); CRYPTOKI_FN_LOG("C_DecryptUpdate"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: std::string decryptverifyupdate(std::string in) {
@code std::string res;
bool decryptverifyupdate() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DecryptVerifyUpdate //! calls @c C_DecryptVerifyUpdate
return check(_slot._init->_fn->C_DecryptVerifyUpdate(_session, CK_BYTE_PTR, CK_ULONG, check(_slot._init->_fn->C_DecryptVerifyUpdate
CK_BYTE_PTR, CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_DecryptVerifyUpdate")); CRYPTOKI_FN_LOG("C_DecryptVerifyUpdate"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: std::string digest(std::string in) {
@code std::string res;
bool digest() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_Digest //! calls @c C_Digest
return check(_slot._init->_fn->C_Digest(_session, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR, check(_slot._init->_fn->C_Digest
CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_Digest")); CRYPTOKI_FN_LOG("C_Digest"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: std::string digestencryptupdate(std::string in) {
@code std::string res;
bool digestencryptupdate() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DigestEncryptUpdate //! calls @c C_DigestEncryptUpdate
return check(_slot._init->_fn->C_DigestEncryptUpdate(_session, CK_BYTE_PTR, CK_ULONG, check(_slot._init->_fn->C_DigestEncryptUpdate
CK_BYTE_PTR, CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_DigestEncryptUpdate")); CRYPTOKI_FN_LOG("C_DigestEncryptUpdate"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
@ -684,15 +754,19 @@ namespace cryptoki {
} }
@endcode */ @endcode */
/*! @todo Not implemented: std::string encrypt(std::string in) {
@code std::string res;
bool encrypt() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_Encrypt //! calls @c C_Encrypt
return check(_slot._init->_fn->C_Encrypt(_session, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR, check(_slot._init->_fn->C_Encrypt
CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_Encrypt")); CRYPTOKI_FN_LOG("C_Encrypt"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
@ -703,15 +777,19 @@ namespace cryptoki {
} }
@endcode */ @endcode */
/*! @todo Not implemented: std::string encryptupdate(std::string in) {
@code std::string res;
bool encryptupdate() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_EncryptUpdate //! calls @c C_EncryptUpdate
return check(_slot._init->_fn->C_EncryptUpdate(_session, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR, check(_slot._init->_fn->C_EncryptUpdate
CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_EncryptUpdate")); CRYPTOKI_FN_LOG("C_EncryptUpdate"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
@ -780,7 +858,7 @@ namespace cryptoki {
@code @code
bool initpin() { bool initpin() {
//! calls @c C_InitPIN //! calls @c C_InitPIN
return check(_init->_fn->C_InitPIN(_session, CK_CHAR_PTR, CK_ULONG), return check(_slot._init->_fn->C_InitPIN(_session, CK_CHAR_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_InitPIN")); CRYPTOKI_FN_LOG("C_InitPIN"));
} }
@endcode */ @endcode */
@ -789,7 +867,7 @@ namespace cryptoki {
@code @code
bool login() { bool login() {
//! calls @c C_Login //! calls @c C_Login
return check(_init->_fn->C_Login(_session, CK_USER_TYPE, CK_CHAR_PTR, CK_ULONG), return check(_slot._init->_fn->C_Login(_session, CK_USER_TYPE, CK_CHAR_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_Login")); CRYPTOKI_FN_LOG("C_Login"));
} }
@endcode */ @endcode */
@ -798,7 +876,7 @@ namespace cryptoki {
@code @code
bool logout() { bool logout() {
//! calls @c C_Logout //! calls @c C_Logout
return check(_init->_fn->C_Logout(_session), return check(_slot._init->_fn->C_Logout(_session),
CRYPTOKI_FN_LOG("C_Logout")); CRYPTOKI_FN_LOG("C_Logout"));
} }
@endcode */ @endcode */
@ -808,7 +886,7 @@ namespace cryptoki {
@code @code
bool seedrandom() { bool seedrandom() {
//! calls @c C_SeedRandom //! calls @c C_SeedRandom
return check(_init->_fn->C_SeedRandom(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_SeedRandom(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SeedRandom")); CRYPTOKI_FN_LOG("C_SeedRandom"));
} }
@endcode */ @endcode */
@ -817,55 +895,67 @@ namespace cryptoki {
@code @code
bool setpin() { bool setpin() {
//! calls @c C_SetPIN //! calls @c C_SetPIN
return check(_init->_fn->C_SetPIN(_session, CK_CHAR_PTR, CK_ULONG, CK_CHAR_PTR, CK_ULONG), return check(_slot._init->_fn->C_SetPIN(_session, CK_CHAR_PTR, CK_ULONG, CK_CHAR_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SetPIN")); CRYPTOKI_FN_LOG("C_SetPIN"));
} }
@endcode */ @endcode */
/*! @todo Not implemented: std::string sign(std::string in) {
@code std::string res;
bool sign() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_Sign //! calls @c C_Sign
return check(_init->_fn->C_Sign(_session, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR, check(_slot._init->_fn->C_Sign
CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_Sign")); CRYPTOKI_FN_LOG("C_Sign"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: std::string signencryptupdate(std::string in) {
@code std::string res;
bool signencryptupdate() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_SignEncryptUpdate //! calls @c C_SignEncryptUpdate
return check(_init->_fn->C_SignEncryptUpdate(_session, CK_BYTE_PTR, CK_ULONG, check(_slot._init->_fn->C_SignEncryptUpdate
CK_BYTE_PTR, CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_SignEncryptUpdate")); CRYPTOKI_FN_LOG("C_SignEncryptUpdate"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool signfinal() { bool signfinal() {
//! calls @c C_SignFinal //! calls @c C_SignFinal
return check(_init->_fn->C_SignFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR), return check(_slot._init->_fn->C_SignFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_SignFinal")); CRYPTOKI_FN_LOG("C_SignFinal"));
} }
@endcode */ @endcode */
/*! @todo Not implemented: std::string signrecover(std::string in) {
@code std::string res;
bool signrecover() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_SignRecover //! calls @c C_SignRecover
return check(_init->_fn->C_SignRecover(_session, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR, check(_slot._init->_fn->C_SignRecover
CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_SignRecover")); CRYPTOKI_FN_LOG("C_SignRecover"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool signupdate() { bool signupdate() {
//! calls @c C_SignUpdate //! calls @c C_SignUpdate
return check(_init->_fn->C_SignUpdate(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_SignUpdate(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SignUpdate")); CRYPTOKI_FN_LOG("C_SignUpdate"));
} }
@endcode */ @endcode */
@ -874,7 +964,8 @@ namespace cryptoki {
@code @code
bool verify() { bool verify() {
//! calls @c C_Verify //! calls @c C_Verify
return check(_init->_fn->C_Verify(_session, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_Verify(_session, CK_BYTE_PTR, CK_ULONG,
CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_Verify")); CRYPTOKI_FN_LOG("C_Verify"));
} }
@endcode */ @endcode */
@ -883,42 +974,48 @@ namespace cryptoki {
@code @code
bool verifyfinal() { bool verifyfinal() {
//! calls @c C_VerifyFinal //! calls @c C_VerifyFinal
return check(_init->_fn->C_VerifyFinal(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_VerifyFinal(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_VerifyFinal")); CRYPTOKI_FN_LOG("C_VerifyFinal"));
} }
@endcode */ @endcode */
/*! @todo Not implemented: std::string verifyrecover(std::string in) {
@code std::string res;
bool verifyrecover() { res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_VerifyRecover //! calls @c C_VerifyRecover
return check(_init->_fn->C_VerifyRecover(_session, CK_BYTE_PTR, CK_ULONG, CK_BYTE_PTR, check(_slot._init->_fn->C_VerifyRecover
CK_ULONG_PTR), (_session,
(unsigned char*)in.begin().operator->(), in.size(),
(unsigned char*)res.begin().operator->(), &size),
CRYPTOKI_FN_LOG("C_VerifyRecover")); CRYPTOKI_FN_LOG("C_VerifyRecover"));
res.resize(size);
return res;
} }
@endcode */
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool verifyupdate() { bool verifyupdate() {
//! calls @c C_VerifyUpdate //! calls @c C_VerifyUpdate
return check(_init->_fn->C_VerifyUpdate(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot._init->_fn->C_VerifyUpdate(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_VerifyUpdate")); CRYPTOKI_FN_LOG("C_VerifyUpdate"));
} }
@endcode */ @endcode */
//@}
}; };
#ifdef NO_OBJECTS_YET //! @todo
class Object { class Object {
private: private:
friend class Session;
Session& _session;
CK_RV _res; CK_RV _res;
bool check(CK_RV result, const std::string& context="") { bool check(CK_RV result, const std::string& context="") {
_res = result; _res = result;
if (_exc && !*this) if (_session._slot._init->_exc && !*this)
if (context.size()) if (context.size())
throw access_error(context+": "+error()); throw access_error(context+": "+error());
else else
@ -926,9 +1023,19 @@ namespace cryptoki {
return _res==CKR_OK; return _res==CKR_OK;
} }
Object(); //! forbidden
Object(Session& session): _session(session), _res(CKR_OK) {}
public: public:
Object(): _res(CKR_OK) {} /*! @name C Like Error Handling
You are strongly recommended not to disable exception
handling. If you disable it, you must check after every
operation whether it was successful or not. These methods
provide all you need for that. */
//@{
/*! @return @c true if last cryptoki on this object call was successful */ /*! @return @c true if last cryptoki on this object call was successful */
operator bool() { operator bool() {
@ -937,14 +1044,16 @@ namespace cryptoki {
/*! @return error text of last cryptoki call */ /*! @return error text of last cryptoki call */
std::string error() { std::string error() {
return error(_res); return _session._slot._init->error(_res);
} }
//@}
/*! @todo Not implemented: /*! @todo Not implemented:
@code @code
bool copyobject() { bool copyobject() {
//! calls @c C_CopyObject //! calls @c C_CopyObject
return check(_init->_fn->C_CopyObject(_session, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_CopyObject(_session, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR), CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_CopyObject")); CRYPTOKI_FN_LOG("C_CopyObject"));
} }
@ -954,7 +1063,7 @@ namespace cryptoki {
@code @code
bool createobject() { bool createobject() {
//! calls @c C_CreateObject //! calls @c C_CreateObject
return check(_init->_fn->C_CreateObject(_session, CK_ATTRIBUTE_PTR, CK_ULONG, return check(_session._slot._init->_fn->C_CreateObject(_session, CK_ATTRIBUTE_PTR, CK_ULONG,
CK_OBJECT_HANDLE_PTR), CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_CreateObject")); CRYPTOKI_FN_LOG("C_CreateObject"));
} }
@ -964,7 +1073,7 @@ namespace cryptoki {
@code @code
bool decryptinit() { bool decryptinit() {
//! calls @c C_DecryptInit //! calls @c C_DecryptInit
return check(_init->_fn->C_DecryptInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_DecryptInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_DecryptInit")); CRYPTOKI_FN_LOG("C_DecryptInit"));
} }
@endcode */ @endcode */
@ -974,7 +1083,7 @@ namespace cryptoki {
@code @code
bool derivekey() { bool derivekey() {
//! calls @c C_DeriveKey //! calls @c C_DeriveKey
return check(_init->_fn->C_DeriveKey(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_DeriveKey(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR), CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_DeriveKey")); CRYPTOKI_FN_LOG("C_DeriveKey"));
} }
@ -984,7 +1093,7 @@ namespace cryptoki {
@code @code
bool destroyobject() { bool destroyobject() {
//! calls @c C_DestroyObject //! calls @c C_DestroyObject
return check(_init->_fn->C_DestroyObject(_session, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_DestroyObject(_session, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_DestroyObject")); CRYPTOKI_FN_LOG("C_DestroyObject"));
} }
@endcode */ @endcode */
@ -994,7 +1103,7 @@ namespace cryptoki {
@code @code
bool digestkey() { bool digestkey() {
//! calls @c C_DigestKey //! calls @c C_DigestKey
return check(_init->_fn->C_DigestKey(_session, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_DigestKey(_session, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_DigestKey")); CRYPTOKI_FN_LOG("C_DigestKey"));
} }
@endcode */ @endcode */
@ -1004,7 +1113,7 @@ namespace cryptoki {
@code @code
bool encryptinit() { bool encryptinit() {
//! calls @c C_EncryptInit //! calls @c C_EncryptInit
return check(_init->_fn->C_EncryptInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_EncryptInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_EncryptInit")); CRYPTOKI_FN_LOG("C_EncryptInit"));
} }
@endcode */ @endcode */
@ -1014,7 +1123,7 @@ namespace cryptoki {
@code @code
bool findobjects() { bool findobjects() {
//! calls @c C_FindObjects //! calls @c C_FindObjects
return check(_init->_fn->C_FindObjects(_session, CK_OBJECT_HANDLE_PTR, CK_ULONG, return check(_session._slot._init->_fn->C_FindObjects(_session, CK_OBJECT_HANDLE_PTR, CK_ULONG,
CK_ULONG_PTR), CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_FindObjects")); CRYPTOKI_FN_LOG("C_FindObjects"));
} }
@ -1024,7 +1133,7 @@ namespace cryptoki {
@code @code
bool generatekey() { bool generatekey() {
//! calls @c C_GenerateKey //! calls @c C_GenerateKey
return check(_init->_fn->C_GenerateKey(_session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR, return check(_session._slot._init->_fn->C_GenerateKey(_session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
CK_ULONG, CK_OBJECT_HANDLE_PTR), CK_ULONG, CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_GenerateKey")); CRYPTOKI_FN_LOG("C_GenerateKey"));
} }
@ -1035,7 +1144,7 @@ namespace cryptoki {
@code @code
bool generatekeypair() { bool generatekeypair() {
//! calls @c C_GenerateKeyPair //! calls @c C_GenerateKeyPair
return check(_init->_fn->C_GenerateKeyPair(_session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR, return check(_session._slot._init->_fn->C_GenerateKeyPair(_session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG, CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG,
CK_OBJECT_HANDLE_PTR, CK_OBJECT_HANDLE_PTR), CK_OBJECT_HANDLE_PTR, CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_GenerateKeyPair")); CRYPTOKI_FN_LOG("C_GenerateKeyPair"));
@ -1046,7 +1155,7 @@ namespace cryptoki {
@code @code
bool getattributevalue() { bool getattributevalue() {
//! calls @c C_GetAttributeValue //! calls @c C_GetAttributeValue
return check(_init->_fn->C_GetAttributeValue(_session, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_GetAttributeValue(_session, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG), CK_ATTRIBUTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_GetAttributeValue")); CRYPTOKI_FN_LOG("C_GetAttributeValue"));
} }
@ -1056,7 +1165,7 @@ namespace cryptoki {
@code @code
bool getobjectsize() { bool getobjectsize() {
//! calls @c C_GetObjectSize //! calls @c C_GetObjectSize
return check(_init->_fn->C_GetObjectSize(_session, CK_OBJECT_HANDLE, CK_ULONG_PTR), return check(_session._slot._init->_fn->C_GetObjectSize(_session, CK_OBJECT_HANDLE, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_GetObjectSize")); CRYPTOKI_FN_LOG("C_GetObjectSize"));
} }
@endcode */ @endcode */
@ -1066,7 +1175,7 @@ namespace cryptoki {
@code @code
bool setattributevalue() { bool setattributevalue() {
//! calls @c C_SetAttributeValue //! calls @c C_SetAttributeValue
return check(_init->_fn->C_SetAttributeValue(_session, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_SetAttributeValue(_session, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG), CK_ATTRIBUTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SetAttributeValue")); CRYPTOKI_FN_LOG("C_SetAttributeValue"));
} }
@ -1076,7 +1185,7 @@ namespace cryptoki {
@code @code
bool setoperationstate() { bool setoperationstate() {
//! calls @c C_SetOperationState //! calls @c C_SetOperationState
return check(_init->_fn->C_SetOperationState(_session, CK_BYTE_PTR, CK_ULONG, return check(_session._slot._init->_fn->C_SetOperationState(_session, CK_BYTE_PTR, CK_ULONG,
CK_OBJECT_HANDLE, CK_OBJECT_HANDLE), CK_OBJECT_HANDLE, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_SetOperationState")); CRYPTOKI_FN_LOG("C_SetOperationState"));
} }
@ -1086,7 +1195,7 @@ namespace cryptoki {
@code @code
bool signinit() { bool signinit() {
//! calls @c C_SignInit //! calls @c C_SignInit
return check(_init->_fn->C_SignInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_SignInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_SignInit")); CRYPTOKI_FN_LOG("C_SignInit"));
} }
@endcode */ @endcode */
@ -1096,7 +1205,7 @@ namespace cryptoki {
@code @code
bool signrecoverinit() { bool signrecoverinit() {
//! calls @c C_SignRecoverInit //! calls @c C_SignRecoverInit
return check(_init->_fn->C_SignRecoverInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_SignRecoverInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_SignRecoverInit")); CRYPTOKI_FN_LOG("C_SignRecoverInit"));
} }
@endcode */ @endcode */
@ -1105,7 +1214,7 @@ namespace cryptoki {
@code @code
bool unwrapkey() { bool unwrapkey() {
//! calls @c C_UnwrapKey //! calls @c C_UnwrapKey
return check(_init->_fn->C_UnwrapKey(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_UnwrapKey(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
CK_BYTE_PTR, CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG, CK_BYTE_PTR, CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG,
CK_OBJECT_HANDLE_PTR), CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_UnwrapKey")); CRYPTOKI_FN_LOG("C_UnwrapKey"));
@ -1116,7 +1225,7 @@ namespace cryptoki {
@code @code
bool verifyinit() { bool verifyinit() {
//! calls @c C_VerifyInit //! calls @c C_VerifyInit
return check(_init->_fn->C_VerifyInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_VerifyInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_VerifyInit")); CRYPTOKI_FN_LOG("C_VerifyInit"));
} }
@endcode */ @endcode */
@ -1126,7 +1235,7 @@ namespace cryptoki {
@code @code
bool verifyrecoverinit() { bool verifyrecoverinit() {
//! calls @c C_VerifyRecoverInit //! calls @c C_VerifyRecoverInit
return check(_init->_fn->C_VerifyRecoverInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot._init->_fn->C_VerifyRecoverInit(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_VerifyRecoverInit")); CRYPTOKI_FN_LOG("C_VerifyRecoverInit"));
} }
@endcode */ @endcode */
@ -1136,7 +1245,7 @@ namespace cryptoki {
@code @code
bool wrapkey() { bool wrapkey() {
//! calls @c C_WrapKey //! calls @c C_WrapKey
return check(_init->_fn->C_WrapKey(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE, return check(_session._slot._init->_fn->C_WrapKey(_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
CK_OBJECT_HANDLE, CK_BYTE_PTR, CK_ULONG_PTR), CK_OBJECT_HANDLE, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_WrapKey")); CRYPTOKI_FN_LOG("C_WrapKey"));
} }
@ -1151,4 +1260,3 @@ namespace cryptoki {
#endif #endif
} }
#endif

@ -7,6 +7,10 @@
include_HEADERS = pcsc.hxx cryptoki.hxx include_HEADERS = pcsc.hxx cryptoki.hxx
lib_LTLIBRARIES = libcryptoki++.la
libcryptoki___la_SOURCES = cryptoki.cxx cryptoki.hxx
if BUILD_WIN if BUILD_WIN
else else
endif endif

Loading…
Cancel
Save