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

@ -19,6 +19,7 @@
#include <cstdlib> // malloc/free #include <cstdlib> // malloc/free
#include <cstring> // memset #include <cstring> // memset
#include <iomanip> #include <iomanip>
#include <memory>
#include <iostream> // debug #include <iostream> // debug
@ -218,14 +219,30 @@ namespace cryptoki {
typedef std::map<CK_ATTRIBUTE_TYPE, Attribute> AttributeMap; typedef std::map<CK_ATTRIBUTE_TYPE, Attribute> AttributeMap;
typedef std::vector<Attribute> AttributeList; typedef std::vector<Attribute> AttributeList;
// class Class {
// public:
// CK_OBJECT_CLASS class;
// };
//class
// //! Map Attribute Class to type // //! Map Attribute Class to type
// /*! @todo to be completed ... */ // /*! @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<CK_ATTRIBUTE_TYPE Attribute> class AttributeType {};
// template<> class AttributeType<CKA_CLASS> { // CRYPTOKI_DECLARE_ATTR(CKA_CLASS, CK_OBJECT_CLASS);
// public: typedef CK_OBJECT_CLASS Type; // CRYPTOKI_DECLARE_ATTR(CKA_HW_FEATURE_TYPE, CK_HW_FEATURE);
// public: typedef Type Param; // 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> { // template<> class AttributeType<CKA_KEY_TYPE> {
// public: typedef CK_KEY_TYPE Type; // public: typedef CK_KEY_TYPE Type;
// public: typedef Type Param; // public: typedef Type Param;
@ -238,10 +255,7 @@ namespace cryptoki {
// public: typedef CKA_BYTE Type; // public: typedef CKA_BYTE Type;
// public: typedef std::string Param; // public: typedef std::string Param;
// }; // };
// template<> class AttributeType<> { // #undef CRYPTOKI_DECLARE_ATTR
// public: typedef Type;
// public: typedef Type Param;
// };
template<std::string::size_type SIZE> template<std::string::size_type SIZE>
class FixString: public std::string { class FixString: public std::string {
@ -583,15 +597,6 @@ namespace cryptoki {
} }
} }
/*! @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 /*! @name C Like Error Handling
You are strongly recommended not to disable exception You are strongly recommended not to disable exception
@ -785,6 +790,7 @@ namespace cryptoki {
class Session { class Session {
private: private:
friend class Login;
friend class Object; friend class Object;
Slot& _slot; Slot& _slot;
@ -819,6 +825,11 @@ namespace cryptoki {
//! Closes actual session //! Closes actual session
~Session() { ~Session() {
try {
_login.reset();
} catch (...) {
if (!std::uncaught_exception()) throw;
}
try { try {
//! calls @c C_CloseSession //! calls @c C_CloseSession
check(_slot._init->_fn->C_CloseSession(_session), check(_slot._init->_fn->C_CloseSession(_session),
@ -1098,24 +1109,45 @@ namespace cryptoki {
} }
@endcode */ @endcode */
/*! @todo Not implemented: class Login {
@code
bool login() { public:
Login(Session& session,
const std::string& pin,
CK_USER_TYPE userType=CKU_USER): _session(session) {
//! calls @c C_Login //! calls @c C_Login
return check(_slot._init->_fn->C_Login(_session, CK_USER_TYPE, CK_CHAR_PTR, CK_ULONG), _session.check(_session._slot._init->_fn->C_Login
(_session._session, userType,
(CK_CHAR*)pin.c_str(),
pin.size()),
CRYPTOKI_FN_LOG("C_Login")); CRYPTOKI_FN_LOG("C_Login"));
} }
@endcode */
/*! @todo Not implemented: ~Login() {
@code try {
bool logout() {
//! calls @c C_Logout //! calls @c C_Logout
return check(_slot._init->_fn->C_Logout(_session), _session.check(_session._slot._init->_fn->C_Logout
(_session._session),
CRYPTOKI_FN_LOG("C_Logout")); CRYPTOKI_FN_LOG("C_Logout"));
} catch (...) {
if (!std::uncaught_exception()) throw;
} }
@endcode */ }
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: /*! @todo Not implemented:
@code @code

Loading…
Cancel
Save