|
|
|
@ -19,6 +19,7 @@ |
|
|
|
|
#include <sstream> |
|
|
|
|
#include <cstdlib> // malloc/free |
|
|
|
|
#include <cstring> // memset |
|
|
|
|
#include <cassert> // assert |
|
|
|
|
#include <iomanip> |
|
|
|
|
#include <memory> |
|
|
|
|
#include <cryptaux.hxx> |
|
|
|
@ -127,6 +128,12 @@ namespace cryptoki { |
|
|
|
|
value = v; |
|
|
|
|
return *this; |
|
|
|
|
} |
|
|
|
|
bool operator==(const Attribute& o) const { |
|
|
|
|
return type==o.type && value==o.value; |
|
|
|
|
} |
|
|
|
|
bool operator!=(const Attribute& o) const { |
|
|
|
|
return type!=o.type || value!=o.value; |
|
|
|
|
} |
|
|
|
|
//! Convert to a @c CK_ATTRIBUTE.
|
|
|
|
|
/*! @note @c pValue points to the internal buffer of this
|
|
|
|
|
element and must therefore not be changed. Also this object |
|
|
|
@ -139,7 +146,7 @@ namespace cryptoki { |
|
|
|
|
a.ulValueLen = value.size(); |
|
|
|
|
return a; |
|
|
|
|
} |
|
|
|
|
std::string name() { |
|
|
|
|
std::string name() const { |
|
|
|
|
switch (type) { |
|
|
|
|
case CKA_CLASS: return "CLASS"; |
|
|
|
|
case CKA_TOKEN: return "TOKEN"; |
|
|
|
@ -205,7 +212,7 @@ namespace cryptoki { |
|
|
|
|
default: return "unknown"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
std::string readableValue() { |
|
|
|
|
std::string readableValue() const { |
|
|
|
|
switch (type) { |
|
|
|
|
case CKA_CLASS: |
|
|
|
|
switch (*((CK_OBJECT_CLASS*)value.begin().operator->())) { |
|
|
|
@ -226,6 +233,10 @@ namespace cryptoki { |
|
|
|
|
value = std::string((char*)&v, sizeof(TYPE)); |
|
|
|
|
return *this; |
|
|
|
|
} |
|
|
|
|
template<typename TYPE> TYPE to() const { |
|
|
|
|
assert(sizeof(TYPE)==value.size()); |
|
|
|
|
return *reinterpret_cast<const TYPE*>(value.begin().operator->()); |
|
|
|
|
} |
|
|
|
|
CK_ATTRIBUTE_TYPE type; |
|
|
|
|
std::string value; |
|
|
|
|
}; |
|
|
|
@ -833,10 +844,12 @@ namespace cryptoki { |
|
|
|
|
|
|
|
|
|
//! Opens a new session.
|
|
|
|
|
/*! @param slot slot to open a session on */ |
|
|
|
|
Session(Slot& slot): _slot(slot), _session(0), _res(CKR_OK) { |
|
|
|
|
Session(Slot& slot, bool rw=false): |
|
|
|
|
_slot(slot), _session(0), _res(CKR_OK) { |
|
|
|
|
//! calls @c C_OpenSession
|
|
|
|
|
check(_slot._init->_fn->C_OpenSession |
|
|
|
|
(_slot._slot, CKF_SERIAL_SESSION, 0, 0, &_session), |
|
|
|
|
(_slot._slot, CKF_SERIAL_SESSION|(rw?CKF_RW_SESSION:0), |
|
|
|
|
0, 0, &_session), |
|
|
|
|
CRYPTOKI_FN_LOG("C_OpenSession")); |
|
|
|
|
//! @todo pass parameter
|
|
|
|
|
} |
|
|
|
@ -1372,14 +1385,14 @@ namespace cryptoki { |
|
|
|
|
} |
|
|
|
|
@endcode */ |
|
|
|
|
|
|
|
|
|
bool decryptinit(CK_MECHANISM_TYPE type, std::string param, |
|
|
|
|
const Object& key) { |
|
|
|
|
//! Call this method on a key object only.
|
|
|
|
|
bool decryptinit(CK_MECHANISM_TYPE type, std::string param) { |
|
|
|
|
CK_MECHANISM mech = { |
|
|
|
|
type, param.begin().operator->(), param.size() |
|
|
|
|
}; |
|
|
|
|
//! calls @c C_DecryptInit
|
|
|
|
|
return check(_session->_slot._init->_fn->C_DecryptInit |
|
|
|
|
(_session->_session, &mech, key._object), |
|
|
|
|
(_session->_session, &mech, _object), |
|
|
|
|
CRYPTOKI_FN_LOG("C_DecryptInit")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1394,14 +1407,12 @@ namespace cryptoki { |
|
|
|
|
} |
|
|
|
|
@endcode */ |
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|
@code |
|
|
|
|
bool destroyobject() { |
|
|
|
|
bool destroy() { |
|
|
|
|
//! calls @c C_DestroyObject
|
|
|
|
|
return check(_session->_slot._init->_fn->C_DestroyObject(_session->_session, CK_OBJECT_HANDLE), |
|
|
|
|
return check(_session->_slot._init->_fn->C_DestroyObject |
|
|
|
|
(_session->_session, _object), |
|
|
|
|
CRYPTOKI_FN_LOG("C_DestroyObject")); |
|
|
|
|
} |
|
|
|
|
@endcode */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! @todo Not implemented:
|
|
|
|
|