destroy object

master
Marc Wäckerlin 15 years ago
parent f962d84383
commit ea6ad617c1
  1. 5
      src/cryptoki.cxx
  2. 35
      src/cryptoki.hxx
  3. 2
      src/pcsc.hxx

@ -277,6 +277,11 @@ namespace cryptoki {
for (AttributeList::size_type i(0); i<attrs.size(); ++i) for (AttributeList::size_type i(0); i<attrs.size(); ++i)
a[i] = attrs[i]; a[i] = attrs[i];
} }
for (AttributeList::size_type i(0); i<attrs.size(); ++i) {
std::string value((char*)a[i].pValue, a[i].ulValueLen);
Attribute xxx(a[i].type, value);
CRYPTOKI_LOG("Attribute: "<<xxx.name()<<" = "<<xxx.readableValue());
};
CK_OBJECT_HANDLE object; CK_OBJECT_HANDLE object;
//! calls @c C_CreateObject //! calls @c C_CreateObject
check(_slot._init->_fn->C_CreateObject check(_slot._init->_fn->C_CreateObject

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

@ -76,7 +76,7 @@
namespace pcsc { namespace pcsc {
//============================================================================ //============================================================================
//! @addtogroup pcsclib //! @addtogroup pcscexceptions
//@{ //@{
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

Loading…
Cancel
Save