master
Marc Wäckerlin 15 years ago
parent 877ed3777f
commit 65d22c37ec
  1. 100
      src/cryptoki.hxx

@ -19,6 +19,7 @@
#include <cstdlib> // malloc/free
#include <cstring> // memset
#include <iomanip>
#include <memory>
#include <iostream> // debug
@ -217,15 +218,31 @@ namespace cryptoki {
};
typedef std::map<CK_ATTRIBUTE_TYPE, Attribute> AttributeMap;
typedef std::vector<Attribute> AttributeList;
// class Class {
// public:
// CK_OBJECT_CLASS class;
// };
//class
// //! Map Attribute Class to type
// /*! @todo to be completed ... */
// #define CRYPTOKI_DECLARE_ATTR(ATTR_ID, TYPE) \
// template<> class AttributeType<ATTR_ID> { \
// public: typedef TYPE Type; \
// }
// template<CK_ATTRIBUTE_TYPE Attribute> class AttributeType {};
// template<> class AttributeType<CKA_CLASS> {
// public: typedef CK_OBJECT_CLASS Type;
// public: typedef Type Param;
// };
// CRYPTOKI_DECLARE_ATTR(CKA_CLASS, CK_OBJECT_CLASS);
// CRYPTOKI_DECLARE_ATTR(CKA_HW_FEATURE_TYPE, CK_HW_FEATURE);
// CRYPTOKI_DECLARE_ATTR(CKA_VALUE, FixString<16>);
// CRYPTOKI_DECLARE_ATTR(CKA_RESET_ON_INIT, CK_BBOOL);
// CRYPTOKI_DECLARE_ATTR(CKA_HAS_RESET, CK_BBOOL);
// // CRYPTOKI_DECLARE_ATTR(CKA_VALUE, ); - byte array
// // CRYPTOKI_DECLARE_ATTR(, );
// // CRYPTOKI_DECLARE_ATTR(, );
// // CRYPTOKI_DECLARE_ATTR(, );
// // CRYPTOKI_DECLARE_ATTR(, );
// template<> class AttributeType<CKA_KEY_TYPE> {
// public: typedef CK_KEY_TYPE Type;
// public: typedef Type Param;
@ -238,10 +255,7 @@ namespace cryptoki {
// public: typedef CKA_BYTE Type;
// public: typedef std::string Param;
// };
// template<> class AttributeType<> {
// public: typedef Type;
// public: typedef Type Param;
// };
// #undef CRYPTOKI_DECLARE_ATTR
template<std::string::size_type SIZE>
class FixString: public std::string {
@ -582,15 +596,6 @@ namespace cryptoki {
if (!std::uncaught_exception()) throw;
}
}
/*! @todo Not implemented:
@code
bool finalize() {
//! calls @c C_Finalize
return check(_slot._init->_fn->C_Finalize(CK_VOID_PTR),
CRYPTOKI_FN_LOG("C_Finalize"));
}
/*! @name C Like Error Handling
@ -785,6 +790,7 @@ namespace cryptoki {
class Session {
private:
friend class Login;
friend class Object;
Slot& _slot;
@ -819,6 +825,11 @@ namespace cryptoki {
//! Closes actual session
~Session() {
try {
_login.reset();
} catch (...) {
if (!std::uncaught_exception()) throw;
}
try {
//! calls @c C_CloseSession
check(_slot._init->_fn->C_CloseSession(_session),
@ -1098,25 +1109,46 @@ namespace cryptoki {
}
@endcode */
/*! @todo Not implemented:
@code
bool login() {
//! calls @c C_Login
return check(_slot._init->_fn->C_Login(_session, CK_USER_TYPE, CK_CHAR_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_Login"));
}
@endcode */
class Login {
public:
Login(Session& session,
const std::string& pin,
CK_USER_TYPE userType=CKU_USER): _session(session) {
//! calls @c C_Login
_session.check(_session._slot._init->_fn->C_Login
(_session._session, userType,
(CK_CHAR*)pin.c_str(),
pin.size()),
CRYPTOKI_FN_LOG("C_Login"));
}
/*! @todo Not implemented:
@code
bool logout() {
//! calls @c C_Logout
return check(_slot._init->_fn->C_Logout(_session),
CRYPTOKI_FN_LOG("C_Logout"));
}
@endcode */
~Login() {
try {
//! calls @c C_Logout
_session.check(_session._slot._init->_fn->C_Logout
(_session._session),
CRYPTOKI_FN_LOG("C_Logout"));
} catch (...) {
if (!std::uncaught_exception()) throw;
}
}
private:
Session& _session;
};
void login(const std::string& pin, CK_USER_TYPE userType=CKU_USER) {
_login = std::auto_ptr<Login>(new Login(*this, pin, userType));
}
void logout() {
_login.reset();
}
std::auto_ptr<Login> _login;
/*! @todo Not implemented:
@code
bool seedrandom() {

Loading…
Cancel
Save