resolve problem with very old compiler (gcc 4.0); refs #28

master
Marc Wäckerlin 11 years ago
parent 50647d461b
commit 84c3301adc
  1. 134
      src/cryptoki.hxx
  2. 4
      src/openssl-engine.hxx

@ -830,6 +830,10 @@ namespace cryptoki {
//@} //@}
Library& library() {
return _library;
}
MechanismInfo mechanisminfo(CK_MECHANISM_TYPE mechanism) { MechanismInfo mechanisminfo(CK_MECHANISM_TYPE mechanism) {
CRYPTOLOG("log"); CRYPTOLOG("log");
MechanismInfo info(mechanism); MechanismInfo info(mechanism);
@ -962,7 +966,7 @@ namespace cryptoki {
bool check(CK_RV result, const std::string& context="") { bool check(CK_RV result, const std::string& context="") {
_res = result; _res = result;
if (_slot._library.exc() && !*this) { if (_slot.library().exc() && !*this) {
if (!context.empty()) { if (!context.empty()) {
throw access_error(context+": "+error()); throw access_error(context+": "+error());
} else { } else {
@ -976,7 +980,7 @@ namespace cryptoki {
void open(bool rw=false) { void open(bool rw=false) {
CRYPTOLOG("references: "<<slots().count(_slot._slot)); CRYPTOLOG("references: "<<slots().count(_slot._slot));
if (slots().count(_slot._slot)==0) { if (slots().count(_slot._slot)==0) {
check(_slot._library->C_OpenSession check(_slot.library()->C_OpenSession
(_slot._slot, CKF_SERIAL_SESSION|(rw?CKF_RW_SESSION:0), (_slot._slot, CKF_SERIAL_SESSION|(rw?CKF_RW_SESSION:0),
0, 0, &_session), 0, 0, &_session),
CRYPTOKI_FN_LOG("C_OpenSession")); CRYPTOKI_FN_LOG("C_OpenSession"));
@ -991,7 +995,7 @@ namespace cryptoki {
CRYPTOLOG("references: "<<slots().count(_slot._slot)); CRYPTOLOG("references: "<<slots().count(_slot._slot));
if (slots().count(_slot._slot)==1) { if (slots().count(_slot._slot)==1) {
slots().erase(slots().find(_slot._slot)); slots().erase(slots().find(_slot._slot));
check(_slot._library->C_CloseSession(_session), check(_slot.library()->C_CloseSession(_session),
CRYPTOKI_FN_LOG("C_CloseSession")); CRYPTOKI_FN_LOG("C_CloseSession"));
} else { } else {
slots().erase(slots().find(_slot._slot)); slots().erase(slots().find(_slot._slot));
@ -1078,7 +1082,7 @@ namespace cryptoki {
/*! @return error text of last cryptoki call */ /*! @return error text of last cryptoki call */
std::string error() { std::string error() {
return _slot._library.error(_res); return _slot.library().error(_res);
} }
//@} //@}
@ -1092,7 +1096,7 @@ namespace cryptoki {
bool cancel() { bool cancel() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_CancelFunction //! calls @c C_CancelFunction
return check(_slot._library->C_CancelFunction(_session), return check(_slot.library()->C_CancelFunction(_session),
CRYPTOKI_FN_LOG("C_CancelFunction")); CRYPTOKI_FN_LOG("C_CancelFunction"));
} }
@ -1105,7 +1109,7 @@ namespace cryptoki {
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_Digest //! calls @c C_Digest
check(_slot._library->C_Digest check(_slot.library()->C_Digest
(_session, (_session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1120,7 +1124,7 @@ namespace cryptoki {
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DigestEncryptUpdate //! calls @c C_DigestEncryptUpdate
check(_slot._library->C_DigestEncryptUpdate check(_slot.library()->C_DigestEncryptUpdate
(_session, (_session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1134,7 +1138,7 @@ namespace cryptoki {
bool digestfinal() { bool digestfinal() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_DigestFinal //! calls @c C_DigestFinal
return check(_slot._library->C_DigestFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR), return check(_slot.library()->C_DigestFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_DigestFinal")); CRYPTOKI_FN_LOG("C_DigestFinal"));
} }
@endcode */ @endcode */
@ -1144,7 +1148,7 @@ namespace cryptoki {
bool digestinit() { bool digestinit() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_DigestInit //! calls @c C_DigestInit
return check(_slot._library->C_DigestInit(_session, CK_MECHANISM_PTR), return check(_slot.library()->C_DigestInit(_session, CK_MECHANISM_PTR),
CRYPTOKI_FN_LOG("C_DigestInit")); CRYPTOKI_FN_LOG("C_DigestInit"));
} }
@endcode */ @endcode */
@ -1154,7 +1158,7 @@ namespace cryptoki {
bool digestupdate() { bool digestupdate() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_DigestUpdate //! calls @c C_DigestUpdate
return check(_slot._library->C_DigestUpdate(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot.library()->C_DigestUpdate(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_DigestUpdate")); CRYPTOKI_FN_LOG("C_DigestUpdate"));
} }
@endcode */ @endcode */
@ -1164,7 +1168,7 @@ namespace cryptoki {
bool findobjectsfinal() { bool findobjectsfinal() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_FindObjectsFinal //! calls @c C_FindObjectsFinal
return check(_slot._library->C_FindObjectsFinal(_session), return check(_slot.library()->C_FindObjectsFinal(_session),
CRYPTOKI_FN_LOG("C_FindObjectsFinal")); CRYPTOKI_FN_LOG("C_FindObjectsFinal"));
} }
@endcode */ @endcode */
@ -1174,7 +1178,7 @@ namespace cryptoki {
bool findobjectsinit() { bool findobjectsinit() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_FindObjectsInit //! calls @c C_FindObjectsInit
return check(_slot._library->C_FindObjectsInit(_session, CK_ATTRIBUTE_PTR, CK_ULONG), return check(_slot.library()->C_FindObjectsInit(_session, CK_ATTRIBUTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_FindObjectsInit")); CRYPTOKI_FN_LOG("C_FindObjectsInit"));
} }
@endcode */ @endcode */
@ -1184,7 +1188,7 @@ namespace cryptoki {
bool findobjects() { bool findobjects() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_FindObjects //! calls @c C_FindObjects
return check(_session->_slot._library->C_FindObjects(_session, CK_OBJECT_HANDLE_PTR, CK_ULONG, return check(_session->_slot.library()->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"));
} }
@ -1195,7 +1199,7 @@ namespace cryptoki {
bool generaterandom() { bool generaterandom() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_GenerateRandom //! calls @c C_GenerateRandom
return check(_slot._library->C_GenerateRandom(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot.library()->C_GenerateRandom(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_GenerateRandom")); CRYPTOKI_FN_LOG("C_GenerateRandom"));
} }
@endcode */ @endcode */
@ -1205,7 +1209,7 @@ namespace cryptoki {
bool getfunctionstatus() { bool getfunctionstatus() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_GetFunctionStatus //! calls @c C_GetFunctionStatus
return check(_slot._library->C_GetFunctionStatus(_session), return check(_slot.library()->C_GetFunctionStatus(_session),
CRYPTOKI_FN_LOG("C_GetFunctionStatus")); CRYPTOKI_FN_LOG("C_GetFunctionStatus"));
} }
@endcode */ @endcode */
@ -1215,7 +1219,7 @@ namespace cryptoki {
bool getoperationstate() { bool getoperationstate() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_GetOperationState //! calls @c C_GetOperationState
return check(_slot._library->C_GetOperationState(_session, CK_BYTE_PTR, CK_ULONG_PTR), return check(_slot.library()->C_GetOperationState(_session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_GetOperationState")); CRYPTOKI_FN_LOG("C_GetOperationState"));
} }
@endcode */ @endcode */
@ -1255,7 +1259,7 @@ namespace cryptoki {
CRYPTOLOG("log"); CRYPTOLOG("log");
CK_SESSION_INFO info; CK_SESSION_INFO info;
//! calls @c C_GetSessionInfo //! calls @c C_GetSessionInfo
check(_slot._library->C_GetSessionInfo(_session, &info), check(_slot.library()->C_GetSessionInfo(_session, &info),
CRYPTOKI_FN_LOG("C_GetSessionInfo")); CRYPTOKI_FN_LOG("C_GetSessionInfo"));
return info; return info;
} }
@ -1276,7 +1280,7 @@ namespace cryptoki {
bool initpin() { bool initpin() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_InitPIN //! calls @c C_InitPIN
return check(_slot._library->C_InitPIN(_session, CK_CHAR_PTR, CK_ULONG), return check(_slot.library()->C_InitPIN(_session, CK_CHAR_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_InitPIN")); CRYPTOKI_FN_LOG("C_InitPIN"));
} }
@endcode */ @endcode */
@ -1292,7 +1296,7 @@ namespace cryptoki {
CK_USER_TYPE userType=CKU_USER): _session(session) { CK_USER_TYPE userType=CKU_USER): _session(session) {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_Login //! calls @c C_Login
_session.check(_session._slot._library->C_Login _session.check(_session._slot.library()->C_Login
(_session._session, userType, (_session._session, userType,
(CK_CHAR*)pin.c_str(), (CK_CHAR*)pin.c_str(),
pin.size()), pin.size()),
@ -1302,7 +1306,7 @@ namespace cryptoki {
~Login() { ~Login() {
try { try {
//! calls @c C_Logout //! calls @c C_Logout
_session.check(_session._slot._library->C_Logout _session.check(_session._slot.library()->C_Logout
(_session._session), (_session._session),
CRYPTOKI_FN_LOG("C_Logout")); CRYPTOKI_FN_LOG("C_Logout"));
} catch (const std::exception& x) { } catch (const std::exception& x) {
@ -1339,7 +1343,7 @@ namespace cryptoki {
bool seedrandom() { bool seedrandom() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_SeedRandom //! calls @c C_SeedRandom
return check(_slot._library->C_SeedRandom(_session, CK_BYTE_PTR, CK_ULONG), return check(_slot.library()->C_SeedRandom(_session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SeedRandom")); CRYPTOKI_FN_LOG("C_SeedRandom"));
} }
@endcode */ @endcode */
@ -1349,7 +1353,7 @@ namespace cryptoki {
bool setpin() { bool setpin() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_SetPIN //! calls @c C_SetPIN
return check(_slot._library->C_SetPIN(_session, CK_CHAR_PTR, CK_ULONG, CK_CHAR_PTR, CK_ULONG), return check(_slot.library()->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 */
@ -1367,7 +1371,7 @@ namespace cryptoki {
bool check(CK_RV result, const std::string& context="") { bool check(CK_RV result, const std::string& context="") {
_res = result; _res = result;
if (_session._slot._library.exc() && !*this) { if (_session._slot.library().exc() && !*this) {
if (!context.empty()) { if (!context.empty()) {
throw access_error(context+": "+error()); throw access_error(context+": "+error());
} else { } else {
@ -1450,7 +1454,7 @@ namespace cryptoki {
/*! @return error text of last cryptoki call */ /*! @return error text of last cryptoki call */
std::string error() { std::string error() {
return _session._slot._library.error(_res); return _session._slot.library().error(_res);
} }
//@} //@}
@ -1466,7 +1470,7 @@ namespace cryptoki {
bool copyobject() { bool copyobject() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_CopyObject //! calls @c C_CopyObject
return check(_session._slot._library->C_CopyObject(_session._session, CK_OBJECT_HANDLE, return check(_session._slot.library()->C_CopyObject(_session._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"));
} }
@ -1480,7 +1484,7 @@ namespace cryptoki {
CRYPTOLOG("decryptinit: type="<<type<<"; mech=("<<mech.mechanism CRYPTOLOG("decryptinit: type="<<type<<"; mech=("<<mech.mechanism
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')'); <<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
//! calls @c C_DecryptInit //! calls @c C_DecryptInit
return check(_session._slot._library->C_DecryptInit return check(_session._slot.library()->C_DecryptInit
(_session._session, &mech, _object), (_session._session, &mech, _object),
CRYPTOKI_FN_LOG("C_DecryptInit")); CRYPTOKI_FN_LOG("C_DecryptInit"));
} }
@ -1492,13 +1496,13 @@ namespace cryptoki {
CK_ULONG size(0); // two calls, first to get minimum buffer length CK_ULONG size(0); // two calls, first to get minimum buffer length
CRYPTOLOG("get size"); CRYPTOLOG("get size");
//! calls @c C_Decrypt //! calls @c C_Decrypt
check(_session._slot._library->C_Decrypt check(_session._slot.library()->C_Decrypt
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), 0, &size), (unsigned char*)&in[0], in.size(), 0, &size),
CRYPTOKI_FN_LOG("C_Decrypt")); CRYPTOKI_FN_LOG("C_Decrypt"));
CRYPTOLOG("maximum size is "<<size<<"Bytes"); CRYPTOLOG("maximum size is "<<size<<"Bytes");
res.resize(size, 0); res.resize(size, 0);
check(_session._slot._library->C_Decrypt check(_session._slot.library()->C_Decrypt
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1514,7 +1518,7 @@ namespace cryptoki {
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DecryptDigestUpdate //! calls @c C_DecryptDigestUpdate
check(_session._slot._library->C_DecryptDigestUpdate check(_session._slot.library()->C_DecryptDigestUpdate
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1526,7 +1530,7 @@ namespace cryptoki {
bool decryptfinal() { bool decryptfinal() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_DecryptFinal //! calls @c C_DecryptFinal
return check(_session._slot._library->C_DecryptFinal return check(_session._slot.library()->C_DecryptFinal
(_session._session, 0, 0), (_session._session, 0, 0),
CRYPTOKI_FN_LOG("C_DecryptFinal")); CRYPTOKI_FN_LOG("C_DecryptFinal"));
//! @todo does this work? //! @todo does this work?
@ -1538,7 +1542,7 @@ namespace cryptoki {
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DecryptUpdate //! calls @c C_DecryptUpdate
check(_session._slot._library->C_DecryptUpdate check(_session._slot.library()->C_DecryptUpdate
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1553,7 +1557,7 @@ namespace cryptoki {
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DecryptVerifyUpdate //! calls @c C_DecryptVerifyUpdate
check(_session._slot._library->C_DecryptVerifyUpdate check(_session._slot.library()->C_DecryptVerifyUpdate
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1567,14 +1571,14 @@ namespace cryptoki {
CRYPTOLOG("log"); CRYPTOLOG("log");
std::string res; std::string res;
CK_ULONG size(0); CK_ULONG size(0);
check(_session._slot._library->C_Sign check(_session._slot.library()->C_Sign
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(),0, &size), (unsigned char*)&in[0], in.size(),0, &size),
CRYPTOKI_FN_LOG("C_Sign")); CRYPTOKI_FN_LOG("C_Sign"));
CRYPTOLOG("maximum size is "<<size<<"Bytes"); CRYPTOLOG("maximum size is "<<size<<"Bytes");
res.resize(size, 0); res.resize(size, 0);
//! calls @c C_Sign //! calls @c C_Sign
check(_session._slot._library->C_Sign check(_session._slot.library()->C_Sign
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1590,7 +1594,7 @@ namespace cryptoki {
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_SignEncryptUpdate //! calls @c C_SignEncryptUpdate
check(_session._slot._library->C_SignEncryptUpdate check(_session._slot.library()->C_SignEncryptUpdate
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1604,7 +1608,7 @@ namespace cryptoki {
bool signfinal() { bool signfinal() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_SignFinal //! calls @c C_SignFinal
return check(_slot._library->C_SignFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR), return check(_slot.library()->C_SignFinal(_session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_SignFinal")); CRYPTOKI_FN_LOG("C_SignFinal"));
} }
@endcode */ @endcode */
@ -1615,7 +1619,7 @@ namespace cryptoki {
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_SignRecover //! calls @c C_SignRecover
check(_session._slot._library->C_SignRecover check(_session._slot.library()->C_SignRecover
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1629,7 +1633,7 @@ namespace cryptoki {
bool signupdate() { bool signupdate() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_SignUpdate //! calls @c C_SignUpdate
return check(_session._slot._library->C_SignUpdate(_session._session, CK_BYTE_PTR, CK_ULONG), return check(_session._slot.library()->C_SignUpdate(_session._session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SignUpdate")); CRYPTOKI_FN_LOG("C_SignUpdate"));
} }
@endcode */ @endcode */
@ -1637,7 +1641,7 @@ namespace cryptoki {
bool verify(std::string data, std::string signature) { bool verify(std::string data, std::string signature) {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_Verify //! calls @c C_Verify
return check(_session._slot._library->C_Verify return check(_session._slot.library()->C_Verify
(_session._session, (_session._session,
(unsigned char*)&data[0], data.size(), (unsigned char*)&data[0], data.size(),
(unsigned char*)&signature[0], signature.size()), (unsigned char*)&signature[0], signature.size()),
@ -1649,7 +1653,7 @@ namespace cryptoki {
bool verifyfinal() { bool verifyfinal() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_VerifyFinal //! calls @c C_VerifyFinal
return check(_session._slot._library->C_VerifyFinal(_session._session, CK_BYTE_PTR, CK_ULONG), return check(_session._slot.library()->C_VerifyFinal(_session._session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_VerifyFinal")); CRYPTOKI_FN_LOG("C_VerifyFinal"));
} }
@endcode */ @endcode */
@ -1660,7 +1664,7 @@ namespace cryptoki {
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_VerifyRecover //! calls @c C_VerifyRecover
check(_session._slot._library->C_VerifyRecover check(_session._slot.library()->C_VerifyRecover
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1674,7 +1678,7 @@ namespace cryptoki {
bool verifyupdate() { bool verifyupdate() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_VerifyUpdate //! calls @c C_VerifyUpdate
return check(_session._slot._library->C_VerifyUpdate(_session._session, CK_BYTE_PTR, CK_ULONG), return check(_session._slot.library()->C_VerifyUpdate(_session._session, CK_BYTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_VerifyUpdate")); CRYPTOKI_FN_LOG("C_VerifyUpdate"));
} }
@endcode */ @endcode */
@ -1685,7 +1689,7 @@ namespace cryptoki {
bool derivekey() { bool derivekey() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_DeriveKey //! calls @c C_DeriveKey
return check(_session._slot._library->C_DeriveKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE, return check(_session._slot.library()->C_DeriveKey(_session._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"));
} }
@ -1694,7 +1698,7 @@ namespace cryptoki {
bool destroy() { bool destroy() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_DestroyObject //! calls @c C_DestroyObject
return check(_session._slot._library->C_DestroyObject return check(_session._slot.library()->C_DestroyObject
(_session._session, _object), (_session._session, _object),
CRYPTOKI_FN_LOG("C_DestroyObject")); CRYPTOKI_FN_LOG("C_DestroyObject"));
} }
@ -1705,7 +1709,7 @@ namespace cryptoki {
bool digestkey() { bool digestkey() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_DigestKey //! calls @c C_DigestKey
return check(_session._slot._library->C_DigestKey(_session._session, CK_OBJECT_HANDLE), return check(_session._slot.library()->C_DigestKey(_session._session, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_DigestKey")); CRYPTOKI_FN_LOG("C_DigestKey"));
} }
@endcode */ @endcode */
@ -1718,7 +1722,7 @@ namespace cryptoki {
CRYPTOLOG("encryptinit: type="<<type<<"; mech=("<<mech.mechanism CRYPTOLOG("encryptinit: type="<<type<<"; mech=("<<mech.mechanism
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')'); <<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
//! calls @c C_EncryptInit //! calls @c C_EncryptInit
return check(_session._slot._library->C_EncryptInit return check(_session._slot.library()->C_EncryptInit
(_session._session, &mech, _object), (_session._session, &mech, _object),
CRYPTOKI_FN_LOG("C_EncryptInit")); CRYPTOKI_FN_LOG("C_EncryptInit"));
} }
@ -1729,13 +1733,13 @@ namespace cryptoki {
CK_ULONG size(0); // two calls, first to get minimum buffer length CK_ULONG size(0); // two calls, first to get minimum buffer length
CRYPTOLOG("get size"); CRYPTOLOG("get size");
//! calls @c C_Encrypt //! calls @c C_Encrypt
check(_session._slot._library->C_Encrypt check(_session._slot.library()->C_Encrypt
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), 0, &size), (unsigned char*)&in[0], in.size(), 0, &size),
CRYPTOKI_FN_LOG("C_Decrypt")); CRYPTOKI_FN_LOG("C_Decrypt"));
CRYPTOLOG("maximum size is "<<size<<"Bytes"); CRYPTOLOG("maximum size is "<<size<<"Bytes");
res.resize(size, 0); res.resize(size, 0);
check(_session._slot._library->C_Encrypt check(_session._slot.library()->C_Encrypt
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1749,7 +1753,7 @@ namespace cryptoki {
bool encryptfinal() { bool encryptfinal() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_EncryptFinal //! calls @c C_EncryptFinal
return check(_session._slot._library->C_EncryptFinal(_session._session, CK_BYTE_PTR, CK_ULONG_PTR), return check(_session._slot.library()->C_EncryptFinal(_session._session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_EncryptFinal")); CRYPTOKI_FN_LOG("C_EncryptFinal"));
} }
@endcode */ @endcode */
@ -1760,7 +1764,7 @@ namespace cryptoki {
res.resize(in.size()); res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_EncryptUpdate //! calls @c C_EncryptUpdate
check(_session._slot._library->C_EncryptUpdate check(_session._slot.library()->C_EncryptUpdate
(_session._session, (_session._session,
(unsigned char*)&in[0], in.size(), (unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size), (unsigned char*)&res[0], &size),
@ -1774,7 +1778,7 @@ namespace cryptoki {
bool generatekey() { bool generatekey() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_GenerateKey //! calls @c C_GenerateKey
return check(_session._slot._library->C_GenerateKey(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR, return check(_session._slot.library()->C_GenerateKey(_session._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"));
} }
@ -1786,7 +1790,7 @@ namespace cryptoki {
bool generatekeypair() { bool generatekeypair() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_GenerateKeyPair //! calls @c C_GenerateKeyPair
return check(_session._slot._library->C_GenerateKeyPair(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR, return check(_session._slot.library()->C_GenerateKeyPair(_session._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"));
@ -1806,7 +1810,7 @@ namespace cryptoki {
Attribute res; Attribute res;
CK_ATTRIBUTE attr((CK_ATTRIBUTE){a, 0, 0}); CK_ATTRIBUTE attr((CK_ATTRIBUTE){a, 0, 0});
//! calls @c C_GetAttributeValue //! calls @c C_GetAttributeValue
if (!check(_session._slot._library->C_GetAttributeValue if (!check(_session._slot.library()->C_GetAttributeValue
(_session._session, _object, &attr, 1), (_session._session, _object, &attr, 1),
CRYPTOKI_FN_LOG("C_GetAttributeValue")) CRYPTOKI_FN_LOG("C_GetAttributeValue"))
|| !(long)attr.ulValueLen>0l) || !(long)attr.ulValueLen>0l)
@ -1815,7 +1819,7 @@ namespace cryptoki {
try { try {
attr.pValue = malloc(attr.ulValueLen); attr.pValue = malloc(attr.ulValueLen);
attr.pValue = memset(attr.pValue, 0, attr.ulValueLen); attr.pValue = memset(attr.pValue, 0, attr.ulValueLen);
if (check(_session._slot._library->C_GetAttributeValue if (check(_session._slot.library()->C_GetAttributeValue
(_session._session, _object, &attr, 1), (_session._session, _object, &attr, 1),
CRYPTOKI_FN_LOG("C_GetAttributeValue"))) CRYPTOKI_FN_LOG("C_GetAttributeValue")))
/*! @todo There's no @c CKA_WRAP_TEMPLATE in Open /*! @todo There's no @c CKA_WRAP_TEMPLATE in Open
@ -1931,7 +1935,7 @@ namespace cryptoki {
attr = (CK_ATTRIBUTE){*it, 0, 0}; attr = (CK_ATTRIBUTE){*it, 0, 0};
try { try {
//! calls @c C_GetAttributeValue //! calls @c C_GetAttributeValue
if (_session._slot._library->C_GetAttributeValue if (_session._slot.library()->C_GetAttributeValue
(_session._session, _object, &attr, 1) (_session._session, _object, &attr, 1)
== CKR_ATTRIBUTE_TYPE_INVALID == CKR_ATTRIBUTE_TYPE_INVALID
|| _res == CKR_ATTRIBUTE_SENSITIVE) { || _res == CKR_ATTRIBUTE_SENSITIVE) {
@ -1941,7 +1945,7 @@ namespace cryptoki {
if ((long)attr.ulValueLen>0l) { if ((long)attr.ulValueLen>0l) {
attr.pValue = malloc(attr.ulValueLen); attr.pValue = malloc(attr.ulValueLen);
attr.pValue = memset(attr.pValue, 0, attr.ulValueLen); attr.pValue = memset(attr.pValue, 0, attr.ulValueLen);
if (check(_session._slot._library->C_GetAttributeValue if (check(_session._slot.library()->C_GetAttributeValue
(_session._session, _object, &attr, 1), (_session._session, _object, &attr, 1),
CRYPTOKI_FN_LOG("C_GetAttributeValue"))) CRYPTOKI_FN_LOG("C_GetAttributeValue")))
/*! @todo There's no @c CKA_WRAP_TEMPLATE in Open /*! @todo There's no @c CKA_WRAP_TEMPLATE in Open
@ -2003,7 +2007,7 @@ namespace cryptoki {
bool getobjectsize() { bool getobjectsize() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_GetObjectSize //! calls @c C_GetObjectSize
return check(_session._slot._library->C_GetObjectSize(_session._session, CK_OBJECT_HANDLE, CK_ULONG_PTR), return check(_session._slot.library()->C_GetObjectSize(_session._session, CK_OBJECT_HANDLE, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_GetObjectSize")); CRYPTOKI_FN_LOG("C_GetObjectSize"));
} }
@endcode */ @endcode */
@ -2014,7 +2018,7 @@ namespace cryptoki {
bool setattributevalue() { bool setattributevalue() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_SetAttributeValue //! calls @c C_SetAttributeValue
return check(_session._slot._library->C_SetAttributeValue(_session._session, CK_OBJECT_HANDLE, return check(_session._slot.library()->C_SetAttributeValue(_session._session, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG), CK_ATTRIBUTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SetAttributeValue")); CRYPTOKI_FN_LOG("C_SetAttributeValue"));
} }
@ -2025,7 +2029,7 @@ namespace cryptoki {
bool setoperationstate() { bool setoperationstate() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_SetOperationState //! calls @c C_SetOperationState
return check(_session._slot._library->C_SetOperationState(_session._session, CK_BYTE_PTR, CK_ULONG, return check(_session._slot.library()->C_SetOperationState(_session._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"));
} }
@ -2039,7 +2043,7 @@ namespace cryptoki {
CRYPTOLOG("signinit: type="<<type<<"; mech=("<<mech.mechanism CRYPTOLOG("signinit: type="<<type<<"; mech=("<<mech.mechanism
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')'); <<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
//! calls @c C_SignInit //! calls @c C_SignInit
return check(_session._slot._library->C_SignInit return check(_session._slot.library()->C_SignInit
(_session._session, &mech, _object), (_session._session, &mech, _object),
CRYPTOKI_FN_LOG("C_SignInit")); CRYPTOKI_FN_LOG("C_SignInit"));
} }
@ -2049,7 +2053,7 @@ namespace cryptoki {
bool signrecoverinit() { bool signrecoverinit() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_SignRecoverInit //! calls @c C_SignRecoverInit
return check(_session._slot._library->C_SignRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot.library()->C_SignRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_SignRecoverInit")); CRYPTOKI_FN_LOG("C_SignRecoverInit"));
} }
@endcode */ @endcode */
@ -2059,7 +2063,7 @@ namespace cryptoki {
bool unwrapkey() { bool unwrapkey() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_UnwrapKey //! calls @c C_UnwrapKey
return check(_session._slot._library->C_UnwrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE, return check(_session._slot.library()->C_UnwrapKey(_session._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"));
@ -2074,7 +2078,7 @@ namespace cryptoki {
CRYPTOLOG("verifyinit: type="<<type<<"; mech=("<<mech.mechanism CRYPTOLOG("verifyinit: type="<<type<<"; mech=("<<mech.mechanism
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')'); <<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
//! calls @c C_VerifyInit //! calls @c C_VerifyInit
return check(_session._slot._library->C_VerifyInit return check(_session._slot.library()->C_VerifyInit
(_session._session, &mech, _object), (_session._session, &mech, _object),
CRYPTOKI_FN_LOG("C_VerifyInit")); CRYPTOKI_FN_LOG("C_VerifyInit"));
} }
@ -2084,7 +2088,7 @@ namespace cryptoki {
bool verifyrecoverinit() { bool verifyrecoverinit() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_VerifyRecoverInit //! calls @c C_VerifyRecoverInit
return check(_session._slot._library->C_VerifyRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE), return check(_session._slot.library()->C_VerifyRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_VerifyRecoverInit")); CRYPTOKI_FN_LOG("C_VerifyRecoverInit"));
} }
@endcode */ @endcode */
@ -2095,7 +2099,7 @@ namespace cryptoki {
bool wrapkey() { bool wrapkey() {
CRYPTOLOG("log"); CRYPTOLOG("log");
//! calls @c C_WrapKey //! calls @c C_WrapKey
return check(_session._slot._library->C_WrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE, return check(_session._slot.library()->C_WrapKey(_session._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"));
} }

@ -32,9 +32,9 @@
#if __GNUC__ >= 2 #if __GNUC__ >= 2
//! Macro for internal OpenSSL checks. //! Macro for internal OpenSSL checks.
/*! You can define a different implementation in your compile call */ /*! You can define a different implementation in your compile call */
#define OPENSSL_CHECK(X) if (!X) {ERR_load_ENGINE_strings(); std::stringstream ss; for (unsigned int err(0); err=ERR_get_error();) ss<<"Error: "<<ERR_error_string(err, 0)<<"; "; ss<<"Command "<<#X<<" failed in function "<<__PRETTY_FUNCTION__<<" in file "<<__FILE__<<":"<<__LINE__; throw std::runtime_error(ss.str());} #define OPENSSL_CHECK(X) if (!(X)) {ERR_load_ENGINE_strings(); std::stringstream ss; for (unsigned int err(0); err=ERR_get_error();) ss<<"Error: "<<ERR_error_string(err, 0)<<"; "; ss<<"Command "<<#X<<" failed in function "<<__PRETTY_FUNCTION__<<" in file "<<__FILE__<<":"<<__LINE__; throw std::runtime_error(ss.str());}
#else #else
#define OPENSSL_CHECK(X) if (!X) {ERR_load_ENGINE_strings(); std::stringstream ss; for (unsigned int err(0); err=ERR_get_error();) ss<<"Error: "<<ERR_error_string(err, 0)<<"; "; ss<<"Command "<<#X<<" failed in file "<<__FILE__<<":"<<__LINE__; throw std::runtime_error(ss.str());} #define OPENSSL_CHECK(X) if (!(X)) {ERR_load_ENGINE_strings(); std::stringstream ss; for (unsigned int err(0); err=ERR_get_error();) ss<<"Error: "<<ERR_error_string(err, 0)<<"; "; ss<<"Command "<<#X<<" failed in file "<<__FILE__<<":"<<__LINE__; throw std::runtime_error(ss.str());}
#endif #endif
#endif #endif

Loading…
Cancel
Save