#include "MscWrappers.h"
inline bool operator == (const MSCObjectInfo &s1, const MSCObjectInfo &s2)
{
return ::strcmp(s1.objectID,s2.objectID)==0;
}
inline bool operator != (const MSCObjectInfo &s1, const MSCObjectInfo &s2)
{
return !(s1 == s2);
}
MscTokenInfo::MscTokenInfo(const MSCTokenInfo &rTokenInfo)
{
tokenAppLen = rTokenInfo.tokenAppLen; tokenIdLength = rTokenInfo.tokenIdLength; tokenState = rTokenInfo.tokenState; tokenType = rTokenInfo.tokenType; addParams = rTokenInfo.addParams; addParamsSize = rTokenInfo.addParamsSize;
::memcpy(tokenName, rTokenInfo.tokenName, sizeof(tokenName)); ::memcpy(slotName, rTokenInfo.slotName, sizeof(slotName)); ::memcpy(svProvider, rTokenInfo.svProvider, sizeof(svProvider)); ::memcpy(reinterpret_cast<unsigned char *>(tokenId), reinterpret_cast<const unsigned char *>(rTokenInfo.tokenId), sizeof(tokenId)); ::memcpy(reinterpret_cast<unsigned char *>(tokenApp), reinterpret_cast<const unsigned char *>(rTokenInfo.tokenApp), sizeof(tokenApp)); }
MscTokenInfo::MscTokenInfo(const SCARD_READERSTATE &readerState)
{
::memset(this, 0, sizeof(*this)); ::strncpy(slotName, readerState.szReader, sizeof(slotName)); size_t idsz = min(size_t(readerState.cbAtr),size_t(sizeof(tokenId)));
::memcpy(reinterpret_cast<unsigned char *>(tokenId), reinterpret_cast<const unsigned char *>(readerState.rgbAtr), idsz); tokenIdLength = idsz;
tokenState = readerState.dwEventState;
}
MscTokenInfo &MscTokenInfo::operator = (const MSCTokenInfo &rTokenInfo)
{
tokenAppLen = rTokenInfo.tokenAppLen; tokenIdLength = rTokenInfo.tokenIdLength; tokenState = rTokenInfo.tokenState; tokenType = rTokenInfo.tokenType; addParams = rTokenInfo.addParams; addParamsSize = rTokenInfo.addParamsSize;
::memcpy(tokenName, rTokenInfo.tokenName, sizeof(tokenName)); ::memcpy(slotName, rTokenInfo.slotName, sizeof(slotName)); ::memcpy(svProvider, rTokenInfo.svProvider, sizeof(svProvider)); ::memcpy(reinterpret_cast<unsigned char *>(tokenId), reinterpret_cast<const unsigned char *>(rTokenInfo.tokenId), sizeof(tokenId)); ::memcpy(reinterpret_cast<unsigned char *>(tokenApp), reinterpret_cast<const unsigned char *>(rTokenInfo.tokenApp), sizeof(tokenApp));
return *this;
}
#pragma mark ---------------- ostream methods --------------
#ifdef _DEBUG_OSTREAM
#include <iomanip>
std::ostream& operator << (std::ostream& strm, const MscObjectACL& oa)
{
strm << "RD: " << oa.readPermission << " WR: " << oa.writePermission << " DEL: " << oa.deletePermission;
return strm;
}
std::ostream& operator << (std::ostream& strm, const MscObjectInfo& oi)
{
strm << "ID: " << oi.objectID << " Size: " << oi.objectSize << " ACL: " << MscObjectACL(oi.objectACL);
return strm;
}
std::ostream& operator << (std::ostream& strm, const MscTokenInfo& ti)
{
strm << "Token name : " << ti.tname() << "\n";
strm << "Slot name : " << ti.sname() << "\n";
strm << "Token id (ATR) : [" << std::dec << ti.tokenIdLength << "] ";
const unsigned char *tid = ti.tid();
for (unsigned int jx=0;jx < ti.tokenIdLength;jx++)
{
strm << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(tid[jx]);
if (((jx+1) % 4)==0)
strm << " ";
}
strm << "\nToken state : " << ti.tokenState << "\n";
strm << "Provider : " << ti.provider() << "\n";
strm << "App ID : [" << std::dec << ti.tokenAppLen << "] " << ti.app() << "\n";
strm << "Type : " << ti.tokenType << "\n";
strm << "Addl Params : [" << ti.addParamsSize << "] " << ti.app() << "\n";
const unsigned char *tap = reinterpret_cast<const unsigned char *>(ti.addParams);
for (unsigned int jx=0;jx < ti.addParamsSize;jx++)
strm << std::hex << std::uppercase << std::setw(2) << std::setfill('0') << tap[jx];
return strm;
}
std::ostream& operator << (std::ostream& strm, const MscStatusInfo& si)
{
strm << "Protocol version : 0x" <<
std::hex << std::uppercase << std::setw(4) << std::setfill('0') << si.appVersion << "\n";
strm << "Applet version : 0x" <<
std::hex << std::uppercase << std::setw(4) << std::setfill('0') << si.swVersion << "\n";
strm << "Total object memory : " <<
std::dec << std::setw(8) << std::setfill('0') << si.totalMemory << "\n";
strm << "Free object memory : " <<
std::dec << std::setw(8) << std::setfill('0') << si.freeMemory << "\n";
strm << "Number of used PINs : " <<
std::dec << std::setw(2) << std::setfill('0') << si.usedPINs << "\n";
strm << "Number of used Keys : " <<
std::dec << std::setw(2) << std::setfill('0') << si.usedKeys << "\n";
strm << "Currently logged identities : 0x" <<
std::hex << std::uppercase << std::setw(4) << std::setfill('0') << si.loggedID << "\n";
return strm;
}
#endif // _DEBUG_OSTREAM