now it compiles again; refs #7

master
Marc Wäckerlin 14 years ago
parent e4671ed7a2
commit fac3d6b34b
  1. 2
      COPYING
  2. 2
      INSTALL
  3. 4
      configure.in
  4. 110
      src/cryptoki.hxx
  5. 22
      test/makefile.am
  6. 111
      test/sharedpointer_test.cxx

@ -1 +1 @@
/opt/local/share/automake-1.11/COPYING
/usr/share/automake-1.11/COPYING

@ -1 +1 @@
/opt/local/share/automake-1.11/INSTALL
/usr/share/automake-1.11/INSTALL

@ -2,7 +2,7 @@
AC_INIT([README])
SRC_DIR=src
TST_DIR=test
TST_DIR=
DOC_DIR=doc
m4_define(x_packagename, libpcscxx)
@ -23,7 +23,7 @@ AM_INIT_AUTOMAKE($PACKAGENAME, $MAJOR.$MINOR.$LEAST, [marc@waeckerlin.org])
# files to create
AC_CONFIG_FILES([makefile
src/makefile test/makefile
src/makefile
doc/doxyfile doc/examples/makefile doc/makefile
src/libpcscxx.pc debian/changelog])

@ -1350,13 +1350,13 @@ namespace cryptoki {
friend class Session;
CK_OBJECT_HANDLE _object;
Session& _session;
Session* _session;
CK_RV _res;
bool check(CK_RV result, const std::string& context="") {
CRYPTOKI_LOG("log");
_res = result;
if (_session._slot._init->_exc && !*this)
if (_session->_slot._init->_exc && !*this)
if (!context.empty())
throw access_error(context+": "+error());
else
@ -1367,20 +1367,12 @@ namespace cryptoki {
Object(); // forbidden
Object(Session& session, CK_OBJECT_HANDLE obj):
_session(session), _object(obj), _res(CKR_OK) {
_session(&session), _object(obj), _res(CKR_OK) {
CRYPTOKI_LOG("log");
}
public:
Object& operator=(Object& o) {
CRYPTOKI_LOG("log");
_object = o._object;
_session = o._session;
_res = o._res;
return *this;
}
/*! @name Comfortable Access
Use these methods in favour of the Low Level Cryptoki
@ -1426,7 +1418,7 @@ namespace cryptoki {
/*! @return error text of last cryptoki call */
std::string error() {
CRYPTOKI_LOG("log");
return _session._slot._init->error(_res);
return _session->_slot._init->error(_res);
}
//@}
@ -1442,7 +1434,7 @@ namespace cryptoki {
bool copyobject() {
CRYPTOKI_LOG("log");
//! calls @c C_CopyObject
return check(_session._slot._init->_fn->C_CopyObject(_session._session, CK_OBJECT_HANDLE,
return check(_session->_slot._init->_fn->C_CopyObject(_session->_session, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_CopyObject"));
}
@ -1456,8 +1448,8 @@ namespace cryptoki {
CRYPTOKI_LOG("decryptinit: type="<<type<<"; mech=("<<mech.mechanism
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
//! calls @c C_DecryptInit
return check(_session._slot._init->_fn->C_DecryptInit
(_session._session, &mech, _object),
return check(_session->_slot._init->_fn->C_DecryptInit
(_session->_session, &mech, _object),
CRYPTOKI_FN_LOG("C_DecryptInit"));
}
@ -1468,14 +1460,14 @@ namespace cryptoki {
CK_ULONG size(0); // two calls, first to get minimum buffer length
CRYPTOKI_LOG("get size");
//! calls @c C_Decrypt
check(_session._slot._init->_fn->C_Decrypt
(_session._session,
check(_session->_slot._init->_fn->C_Decrypt
(_session->_session,
(unsigned char*)&in[0], in.size(), 0, &size),
CRYPTOKI_FN_LOG("C_Decrypt"));
CRYPTOKI_LOG("maximum size is "<<size<<"Bytes");
res.resize(size, 0);
check(_session._slot._init->_fn->C_Decrypt
(_session._session,
check(_session->_slot._init->_fn->C_Decrypt
(_session->_session,
(unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size),
CRYPTOKI_FN_LOG("C_Decrypt"));
@ -1490,8 +1482,8 @@ namespace cryptoki {
res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DecryptDigestUpdate
check(_session._slot._init->_fn->C_DecryptDigestUpdate
(_session._session,
check(_session->_slot._init->_fn->C_DecryptDigestUpdate
(_session->_session,
(unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size),
CRYPTOKI_FN_LOG("C_DecryptDigestUpdate"));
@ -1502,8 +1494,8 @@ namespace cryptoki {
bool decryptfinal() {
CRYPTOKI_LOG("log");
//! calls @c C_DecryptFinal
return check(_session._slot._init->_fn->C_DecryptFinal
(_session._session, 0, 0),
return check(_session->_slot._init->_fn->C_DecryptFinal
(_session->_session, 0, 0),
CRYPTOKI_FN_LOG("C_DecryptFinal"));
//! @todo does this work?
}
@ -1514,8 +1506,8 @@ namespace cryptoki {
res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DecryptUpdate
check(_session._slot._init->_fn->C_DecryptUpdate
(_session._session,
check(_session->_slot._init->_fn->C_DecryptUpdate
(_session->_session,
(unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size),
CRYPTOKI_FN_LOG("C_DecryptUpdate"));
@ -1529,8 +1521,8 @@ namespace cryptoki {
res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_DecryptVerifyUpdate
check(_session._slot._init->_fn->C_DecryptVerifyUpdate
(_session._session,
check(_session->_slot._init->_fn->C_DecryptVerifyUpdate
(_session->_session,
(unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size),
CRYPTOKI_FN_LOG("C_DecryptVerifyUpdate"));
@ -1543,7 +1535,7 @@ namespace cryptoki {
bool derivekey() {
CRYPTOKI_LOG("log");
//! calls @c C_DeriveKey
return check(_session._slot._init->_fn->C_DeriveKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
return check(_session->_slot._init->_fn->C_DeriveKey(_session->_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG, CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_DeriveKey"));
}
@ -1552,8 +1544,8 @@ namespace cryptoki {
bool destroy() {
CRYPTOKI_LOG("log");
//! calls @c C_DestroyObject
return check(_session._slot._init->_fn->C_DestroyObject
(_session._session, _object),
return check(_session->_slot._init->_fn->C_DestroyObject
(_session->_session, _object),
CRYPTOKI_FN_LOG("C_DestroyObject"));
}
@ -1563,7 +1555,7 @@ namespace cryptoki {
bool digestkey() {
CRYPTOKI_LOG("log");
//! calls @c C_DigestKey
return check(_session._slot._init->_fn->C_DigestKey(_session._session, CK_OBJECT_HANDLE),
return check(_session->_slot._init->_fn->C_DigestKey(_session->_session, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_DigestKey"));
}
@endcode */
@ -1576,8 +1568,8 @@ namespace cryptoki {
CRYPTOKI_LOG("encryptinit: type="<<type<<"; mech=("<<mech.mechanism
<<", "<<mech.pParameter<<", "<<mech.ulParameterLen<<')');
//! calls @c C_EncryptInit
return check(_session._slot._init->_fn->C_EncryptInit
(_session._session, &mech, _object),
return check(_session->_slot._init->_fn->C_EncryptInit
(_session->_session, &mech, _object),
CRYPTOKI_FN_LOG("C_EncryptInit"));
}
@ -1587,14 +1579,14 @@ namespace cryptoki {
CK_ULONG size(0); // two calls, first to get minimum buffer length
CRYPTOKI_LOG("get size");
//! calls @c C_Encrypt
check(_session._slot._init->_fn->C_Encrypt
(_session._session,
check(_session->_slot._init->_fn->C_Encrypt
(_session->_session,
(unsigned char*)&in[0], in.size(), 0, &size),
CRYPTOKI_FN_LOG("C_Decrypt"));
CRYPTOKI_LOG("maximum size is "<<size<<"Bytes");
res.resize(size, 0);
check(_session._slot._init->_fn->C_Encrypt
(_session._session,
check(_session->_slot._init->_fn->C_Encrypt
(_session->_session,
(unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size),
CRYPTOKI_FN_LOG("C_Encrypt"));
@ -1607,7 +1599,7 @@ namespace cryptoki {
bool encryptfinal() {
CRYPTOKI_LOG("log");
//! calls @c C_EncryptFinal
return check(_session._slot._init->_fn->C_EncryptFinal(_session._session, CK_BYTE_PTR, CK_ULONG_PTR),
return check(_session->_slot._init->_fn->C_EncryptFinal(_session->_session, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_EncryptFinal"));
}
@endcode */
@ -1618,8 +1610,8 @@ namespace cryptoki {
res.resize(in.size());
CK_ULONG size(res.size()); //! @todo check if size is ok
//! calls @c C_EncryptUpdate
check(_session._slot._init->_fn->C_EncryptUpdate
(_session._session,
check(_session->_slot._init->_fn->C_EncryptUpdate
(_session->_session,
(unsigned char*)&in[0], in.size(),
(unsigned char*)&res[0], &size),
CRYPTOKI_FN_LOG("C_EncryptUpdate"));
@ -1632,7 +1624,7 @@ namespace cryptoki {
bool generatekey() {
CRYPTOKI_LOG("log");
//! calls @c C_GenerateKey
return check(_session._slot._init->_fn->C_GenerateKey(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
return check(_session->_slot._init->_fn->C_GenerateKey(_session->_session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
CK_ULONG, CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_GenerateKey"));
}
@ -1644,7 +1636,7 @@ namespace cryptoki {
bool generatekeypair() {
CRYPTOKI_LOG("log");
//! calls @c C_GenerateKeyPair
return check(_session._slot._init->_fn->C_GenerateKeyPair(_session._session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
return check(_session->_slot._init->_fn->C_GenerateKeyPair(_session->_session, CK_MECHANISM_PTR, CK_ATTRIBUTE_PTR,
CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG,
CK_OBJECT_HANDLE_PTR, CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_GenerateKeyPair"));
@ -1664,8 +1656,8 @@ namespace cryptoki {
Attribute res;
CK_ATTRIBUTE attr((CK_ATTRIBUTE){a, 0, 0});
//! calls @c C_GetAttributeValue
if (!check(_session._slot._init->_fn->C_GetAttributeValue
(_session._session, _object, &attr, 1),
if (!check(_session->_slot._init->_fn->C_GetAttributeValue
(_session->_session, _object, &attr, 1),
CRYPTOKI_FN_LOG("C_GetAttributeValue"))
|| !(long)attr.ulValueLen>0l)
//! Without exception handling, size and type must be checked too.
@ -1673,8 +1665,8 @@ namespace cryptoki {
try {
attr.pValue = malloc(attr.ulValueLen);
attr.pValue = memset(attr.pValue, 0, attr.ulValueLen);
if (check(_session._slot._init->_fn->C_GetAttributeValue
(_session._session, _object, &attr, 1),
if (check(_session->_slot._init->_fn->C_GetAttributeValue
(_session->_session, _object, &attr, 1),
CRYPTOKI_FN_LOG("C_GetAttributeValue")))
/*! @todo There's no @c CKA_WRAP_TEMPLATE in Open
Cryptoki. From the Specs: «In the special case
@ -1789,8 +1781,8 @@ namespace cryptoki {
attr = (CK_ATTRIBUTE){*it, 0, 0};
try {
//! calls @c C_GetAttributeValue
if (_session._slot._init->_fn->C_GetAttributeValue
(_session._session, _object, &attr, 1)
if (_session->_slot._init->_fn->C_GetAttributeValue
(_session->_session, _object, &attr, 1)
== CKR_ATTRIBUTE_TYPE_INVALID
|| _res == CKR_ATTRIBUTE_SENSITIVE) {
continue; //! Ignores unsupported Attributes.
@ -1799,8 +1791,8 @@ namespace cryptoki {
if ((long)attr.ulValueLen>0l) {
attr.pValue = malloc(attr.ulValueLen);
attr.pValue = memset(attr.pValue, 0, attr.ulValueLen);
if (check(_session._slot._init->_fn->C_GetAttributeValue
(_session._session, _object, &attr, 1),
if (check(_session->_slot._init->_fn->C_GetAttributeValue
(_session->_session, _object, &attr, 1),
CRYPTOKI_FN_LOG("C_GetAttributeValue")))
/*! @todo There's no @c CKA_WRAP_TEMPLATE in Open
Cryptoki. From the Specs: «In the special
@ -1861,7 +1853,7 @@ namespace cryptoki {
bool getobjectsize() {
CRYPTOKI_LOG("log");
//! calls @c C_GetObjectSize
return check(_session._slot._init->_fn->C_GetObjectSize(_session._session, CK_OBJECT_HANDLE, CK_ULONG_PTR),
return check(_session->_slot._init->_fn->C_GetObjectSize(_session->_session, CK_OBJECT_HANDLE, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_GetObjectSize"));
}
@endcode */
@ -1872,7 +1864,7 @@ namespace cryptoki {
bool setattributevalue() {
CRYPTOKI_LOG("log");
//! calls @c C_SetAttributeValue
return check(_session._slot._init->_fn->C_SetAttributeValue(_session._session, CK_OBJECT_HANDLE,
return check(_session->_slot._init->_fn->C_SetAttributeValue(_session->_session, CK_OBJECT_HANDLE,
CK_ATTRIBUTE_PTR, CK_ULONG),
CRYPTOKI_FN_LOG("C_SetAttributeValue"));
}
@ -1883,7 +1875,7 @@ namespace cryptoki {
bool setoperationstate() {
CRYPTOKI_LOG("log");
//! calls @c C_SetOperationState
return check(_session._slot._init->_fn->C_SetOperationState(_session._session, CK_BYTE_PTR, CK_ULONG,
return check(_session->_slot._init->_fn->C_SetOperationState(_session->_session, CK_BYTE_PTR, CK_ULONG,
CK_OBJECT_HANDLE, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_SetOperationState"));
}
@ -1894,7 +1886,7 @@ namespace cryptoki {
bool signinit() {
CRYPTOKI_LOG("log");
//! calls @c C_SignInit
return check(_session._slot._init->_fn->C_SignInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
return check(_session->_slot._init->_fn->C_SignInit(_session->_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_SignInit"));
}
@endcode */
@ -1905,7 +1897,7 @@ namespace cryptoki {
bool signrecoverinit() {
CRYPTOKI_LOG("log");
//! calls @c C_SignRecoverInit
return check(_session._slot._init->_fn->C_SignRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
return check(_session->_slot._init->_fn->C_SignRecoverInit(_session->_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_SignRecoverInit"));
}
@endcode */
@ -1915,7 +1907,7 @@ namespace cryptoki {
bool unwrapkey() {
CRYPTOKI_LOG("log");
//! calls @c C_UnwrapKey
return check(_session._slot._init->_fn->C_UnwrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
return check(_session->_slot._init->_fn->C_UnwrapKey(_session->_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
CK_BYTE_PTR, CK_ULONG, CK_ATTRIBUTE_PTR, CK_ULONG,
CK_OBJECT_HANDLE_PTR),
CRYPTOKI_FN_LOG("C_UnwrapKey"));
@ -1927,7 +1919,7 @@ namespace cryptoki {
bool verifyinit() {
CRYPTOKI_LOG("log");
//! calls @c C_VerifyInit
return check(_session._slot._init->_fn->C_VerifyInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
return check(_session->_slot._init->_fn->C_VerifyInit(_session->_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_VerifyInit"));
}
@endcode */
@ -1938,7 +1930,7 @@ namespace cryptoki {
bool verifyrecoverinit() {
CRYPTOKI_LOG("log");
//! calls @c C_VerifyRecoverInit
return check(_session._slot._init->_fn->C_VerifyRecoverInit(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
return check(_session->_slot._init->_fn->C_VerifyRecoverInit(_session->_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE),
CRYPTOKI_FN_LOG("C_VerifyRecoverInit"));
}
@endcode */
@ -1949,7 +1941,7 @@ namespace cryptoki {
bool wrapkey() {
CRYPTOKI_LOG("log");
//! calls @c C_WrapKey
return check(_session._slot._init->_fn->C_WrapKey(_session._session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
return check(_session->_slot._init->_fn->C_WrapKey(_session->_session, CK_MECHANISM_PTR, CK_OBJECT_HANDLE,
CK_OBJECT_HANDLE, CK_BYTE_PTR, CK_ULONG_PTR),
CRYPTOKI_FN_LOG("C_WrapKey"));
}

@ -1,22 +0,0 @@
## @id $Id$
## 1 2 3 4 5 6 7 8
## 45678901234567890123456789012345678901234567890123456789012345678901234567890
AM_CXXFLAGS = -I ${top_srcdir}/src
AM_LDFLAGS = -L${top_builddir}/src
LDADD = -lcppunit
if MAC
AM_LDFLAGS += -L/opt/local/lib
AM_CPPFLAGS += -I/opt/local/include
endif
check_PROGRAMS = sharedpointer_test
TESTS=${check_PROGRAMS}
sharedpointer_test_SOURCES = sharedpointer_test.cxx
sharedpointer_test_LDFLAGS = -L${top_builddir}/src -lcryptoki++
CLEANFILES = $(check_PROGRAMS:%=%.xml)
MAINTAINERCLEANFILES = makefile.in

@ -1,111 +0,0 @@
/*! @file
@id $Id$
*/
// 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
#include <cryptoki.hxx>
#include <cppunit/TestFixture.h>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/XmlOutputter.h>
#include <fstream>
using namespace cryptoki;
template <typename T> class SharedPointerInside: public SharedPointer<T> {
public:
SharedPointerInside() {}
SharedPointerInside(const SharedPointerInside& o):
SharedPointer<T>(o) {}
SharedPointerInside(T* p): SharedPointer<T>(p) {}
~SharedPointerInside() {
SmartResource::destruct();
}
SharedPointerInside& operator=(const SharedPointerInside& o) {
return reset(o), *this;
}
SharedPointerInside& operator=(T* p) {
return reset(p), *this;
}
int cnt() {
return SharedPointer<T>::cnt();
}
static int freed() {
return _free;
}
protected:
void free() {
++_free;
SharedPointer<T>::free();
}
private:
static int _free;
};
template<typename T> int SharedPointerInside<T>::_free(0);
class SharedPointerTest: public CppUnit::TestFixture {
public:
void check() {
{
SharedPointerInside<int> i, j(new int);
CPPUNIT_ASSERT_EQUAL(0, SharedPointerInside<int>::freed());
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
CPPUNIT_ASSERT_EQUAL(1, j.cnt());
i = j;
CPPUNIT_ASSERT_EQUAL(1, SharedPointerInside<int>::freed());
CPPUNIT_ASSERT_EQUAL(i.get(), j.get());
CPPUNIT_ASSERT_EQUAL(2, i.cnt());
CPPUNIT_ASSERT_EQUAL(2, j.cnt());
*i = 5;
CPPUNIT_ASSERT_EQUAL(1, SharedPointerInside<int>::freed());
CPPUNIT_ASSERT_EQUAL(5, *j);
CPPUNIT_ASSERT_EQUAL(2, i.cnt());
CPPUNIT_ASSERT_EQUAL(2, j.cnt());
int* old(j.get());
i = new int(6);
CPPUNIT_ASSERT_EQUAL(1, SharedPointerInside<int>::freed());
CPPUNIT_ASSERT_EQUAL(5, *j);
CPPUNIT_ASSERT_EQUAL(6, *i);
CPPUNIT_ASSERT(i.get()!=j.get());
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
CPPUNIT_ASSERT_EQUAL(1, j.cnt());
i = new int(8);
CPPUNIT_ASSERT_EQUAL(2, SharedPointerInside<int>::freed());
CPPUNIT_ASSERT_EQUAL(5, *j);
CPPUNIT_ASSERT_EQUAL(8, *i);
CPPUNIT_ASSERT(i.get()!=j.get());
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
CPPUNIT_ASSERT_EQUAL(1, j.cnt());
{
SharedPointerInside<int> k(j);
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
CPPUNIT_ASSERT_EQUAL(2, j.cnt());
CPPUNIT_ASSERT_EQUAL(2, k.cnt());
}
CPPUNIT_ASSERT_EQUAL(2, SharedPointerInside<int>::freed());
CPPUNIT_ASSERT_EQUAL(1, i.cnt());
CPPUNIT_ASSERT_EQUAL(1, j.cnt());
}
CPPUNIT_ASSERT_EQUAL(4, SharedPointerInside<int>::freed());
}
CPPUNIT_TEST_SUITE(SharedPointerTest);
CPPUNIT_TEST(check);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(SharedPointerTest);
int main(int argc, char** argv) try {
std::ofstream ofs((*argv+std::string(".xml")).c_str());
CppUnit::TextUi::TestRunner runner;
runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), ofs));
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
return runner.run() ? 0 : 1;
} catch (std::exception& e) {
std::cerr<<"***Exception: "<<e.what()<<std::endl;
return 1;
}
Loading…
Cancel
Save