#ifndef _H_UTILITIES_ERROR
#define _H_UTILITIES_ERROR
#include <AvailabilityMacros.h>
#include <exception>
#include <errno.h>
#include <Security/SecBase.h>
#include <set>
#undef check
namespace Security {
class CommonError : public std::exception {
protected:
CommonError();
CommonError(const CommonError &source);
public:
virtual ~CommonError() throw ();
virtual OSStatus osStatus() const = 0;
virtual int unixError() const = 0;
char whatBuffer[128];
const size_t whatBufferSize = sizeof(whatBuffer);
static void LogBacktrace();
};
class UnixError : public CommonError {
protected:
UnixError();
UnixError(int err);
public:
const int error;
virtual OSStatus osStatus() const;
virtual int unixError() const;
virtual const char *what () const throw ();
static void check(int result) { if (result == -1) throwMe(); }
static void throwMe(int err = errno) __attribute__((noreturn));
static UnixError make(int err = errno) DEPRECATED_ATTRIBUTE;
};
class MacOSError : public CommonError {
protected:
MacOSError(int err);
public:
const int error;
virtual OSStatus osStatus() const;
virtual int unixError() const;
virtual const char *what () const throw ();
static void check(OSStatus status) { if (status != errSecSuccess) throwMe(status); }
static void throwMe(int err) __attribute__((noreturn));
static MacOSError make(int err);
};
typedef std::set<OSStatus> MacOSErrorSet;
class CFError : public CommonError {
protected:
CFError();
public:
virtual OSStatus osStatus() const;
virtual int unixError() const;
virtual const char *what () const throw ();
template <class T>
static void check(const T &p) { if (!p) throwMe(); }
static void throwMe() __attribute__((noreturn));
};
class ModuleNexusError : public CommonError {
protected:
ModuleNexusError() {}
public:
virtual OSStatus osStatus() const;
virtual int unixError() const;
static void throwMe() __attribute__((noreturn));
};
}
#endif //_H_UTILITIES_ERROR