#include "PIVError.h"
#include <Security/cssmerr.h>
PIVError::PIVError(uint16_t sw) : SCardError(sw)
{
#if MAX_OS_X_VERSION_MIN_REQUIRED <= MAX_OS_X_VERSION_10_5
IFDEBUG(debugDiagnose(this));
#else
SECURITY_EXCEPTION_THROW_OTHER(this, sw, (char *)"PIV");
#endif
}
PIVError::~PIVError() throw ()
{
}
const char *PIVError::what() const throw ()
{ return "PIV error"; }
OSStatus PIVError::osStatus() const
{
switch (statusWord)
{
case PIV_AUTHENTICATION_FAILED_0:
case PIV_AUTHENTICATION_FAILED_1:
case PIV_AUTHENTICATION_FAILED_2:
case PIV_AUTHENTICATION_FAILED_3:
return CSSM_ERRCODE_OPERATION_AUTH_DENIED;
default:
return SCardError::osStatus();
}
}
void PIVError::throwMe(uint16_t sw)
{ throw PIVError(sw); }
#if !defined(NDEBUG)
#if MAX_OS_X_VERSION_MIN_REQUIRED <= MAX_OS_X_VERSION_10_5
void PIVError::debugDiagnose(const void *id) const
{
secdebug("exception", "%p PIVError %s (%04hX)",
id, errorstr(statusWord), statusWord);
}
#endif // MAX_OS_X_VERSION_MIN_REQUIRED <= MAX_OS_X_VERSION_10_5
const char *PIVError::errorstr(uint16_t sw) const
{
switch (sw)
{
case PIV_AUTHENTICATION_FAILED_0:
return "Authentication failed, 0 retries left.";
case PIV_AUTHENTICATION_FAILED_1:
return "Authentication failed, 1 retry left.";
case PIV_AUTHENTICATION_FAILED_2:
return "Authentication failed, 2 retries left.";
case PIV_AUTHENTICATION_FAILED_3:
return "Authentication failed, 3 retries left.";
default:
return SCardError::errorstr(sw);
}
}
#endif //NDEBUG