#ifndef _H_MUSCLE_PP
#define _H_MUSCLE_PP
#include <security_utilities/refcount.h>
#include <security_utilities/pcsc++.h>
#include <PCSC/musclecard.h>
#include <set>
namespace Security {
namespace Muscle {
class Error : public CommonError {
public:
Error(MSC_RV err);
const MSC_RV error;
OSStatus osStatus() const;
int unixError() const;
const char *what () const throw ();
static void check(MSC_RV err) { if (err != MSC_SUCCESS) throwMe(err); }
static void throwMe(MSC_RV err);
};
class ACL {
public:
typedef MSCUShort16 Value;
ACL(Value write = MSC_AUT_ALL, Value read = MSC_AUT_ALL, Value erase = MSC_AUT_ALL);
ACL() { mRead = mWrite = mErase = MSC_AUT_ALL; }
operator MSCKeyACL () const;
operator MSCObjectACL () const;
Value read() const { return mRead; }
bool read(Value mask) const { return mRead & mask; }
Value &read() { return mRead; }
Value write() const { return mWrite; }
bool write(Value mask) const { return mWrite & mask; }
Value &write() { return mWrite; }
Value erase() const { return mErase; }
bool erase(Value mask) const { return mErase & mask; }
Value &erase() { return mErase; }
Value use() const { return mErase; }
bool use(Value mask) const { return mErase & mask; }
Value &use() { return mErase; }
string form(char ue) const;
private:
MSCUShort16 mRead;
MSCUShort16 mWrite;
MSCUShort16 mErase;
};
class CardItem : public RefCount {
protected:
CardItem() { }
public:
virtual ~CardItem();
virtual unsigned size() const = 0;
virtual const char *name() const = 0;
virtual const ACL &acl() const = 0;
virtual ACL &acl() = 0;
virtual void debugDump() = 0;
bool operator < (const CardItem &other) const { return this < &other; }
};
class Key : public CardItem, public MSCKeyInfo {
public:
Key(const MSCKeyInfo &info);
unsigned id() const { return this->keyNum; }
const char *name() const;
unsigned type() const { return this->keyType; }
unsigned size() const;
unsigned mode() const { return this->keyPolicy.cipherMode; }
unsigned operations() const { return this->keyPolicy.cipherDirection; }
const ACL &acl() const;
ACL &acl();
void debugDump();
private:
char mKeyName[8]; };
class Object : public CardItem, public MSCObjectInfo {
public:
Object(const MSCObjectInfo &info) : MSCObjectInfo(info) { }
const char *name() const;
unsigned size() const;
const ACL &acl() const;
ACL &acl();
void debugDump();
};
class Transaction;
class Connection : public MSCTokenConnection, public MSCStatusInfo {
public:
Connection();
~Connection();
void open(const PCSC::ReaderState &reader, unsigned share = MSC_SHARE_EXCLUSIVE);
void close();
operator bool () const { return mIsOpen; }
void begin(Transaction *trans = NULL);
void end(Transaction *trans = NULL);
Transaction *currentTransaction() const;
typedef set<RefPointer<CardItem> > ItemSet;
void getItems(ItemSet &items, bool getKeys = true, bool getOthers = true);
void updateStatus();
private:
bool mIsOpen;
Transaction *mCurrentTransaction;
};
class Transaction {
public:
Transaction(Connection &con);
~Transaction();
Connection &connection;
};
} }
#endif //_H_MUSCLE_PP