#ifdef __MWERKS__
#define _CPP_CSSMERRNO
#endif
#include <Security/cssmerrno.h>
#include <Security/globalizer.h>
#include <stdio.h>
#include <map>
namespace Security {
struct ErrorMap : public map<CSSM_RETURN, const char *> {
ErrorMap();
};
static ModuleNexus<ErrorMap> errorMap;
struct Mapping {
CSSM_RETURN error;
const char *name;
};
#include "errorcodes.gen" // include generated error tables
ErrorMap::ErrorMap()
{
for (unsigned n = 0; n < sizeof(errorList) / sizeof(errorList[0]); n++)
(*this)[errorList[n].error] = errorList[n].name;
}
extern "C"
void cssmPerror(const char *how, CSSM_RETURN error)
{
if (how)
fprintf(stderr, "%s: %s\n", how, cssmErrorString(error).c_str());
else
fprintf(stderr, "%s\n", cssmErrorString(error).c_str());
}
string cssmErrorString(CSSM_RETURN error)
{
if (error == CSSM_OK) {
return "[ok]";
} else if (error > 0 &&
int(error) < int(sizeof(convErrorList) / sizeof(convErrorList[0]))) {
return string("COMMON[") + convErrorList[error] + "]";
} else {
ErrorMap::const_iterator it = errorMap().find(error);
if (it == errorMap().end())
return "[UNKNOWN]";
else
return it->second;
}
}
string cssmErrorString(const CssmCommonError &error)
{ return cssmErrorString(error.cssmError()); }
}