]>
git.saurik.com Git - apple/security.git/blob - OSX/include/security_utilities/errors.h
2 * Copyright (c) 2000-2004,2011-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 #ifndef _H_UTILITIES_ERROR
29 #define _H_UTILITIES_ERROR
31 #include <AvailabilityMacros.h>
34 #include <Security/SecBase.h>
43 // Common base of Security exceptions that represent error conditions.
44 // All can yield Unix or OSStatus error codes as needed, though *how*
45 // is up to the subclass implementation.
46 // CSSM_RETURN conversions are done externally in (???).
48 class CommonError
: public std::exception
{
51 CommonError(const CommonError
&source
);
53 virtual ~CommonError() throw ();
55 virtual OSStatus
osStatus() const = 0;
56 virtual int unixError() const = 0;
61 // Genuine Unix-originated errors identified by an errno value.
62 // This includes secondary sources such as pthreads.
64 class UnixError
: public CommonError
{
70 virtual OSStatus
osStatus() const;
71 virtual int unixError() const;
72 virtual const char *what () const throw ();
74 static void check(int result
) { if (result
== -1) throwMe(); }
75 static void throwMe(int err
= errno
) __attribute__((noreturn
));
77 // @@@ This is a hack for the Network protocol state machine
78 static UnixError
make(int err
= errno
) DEPRECATED_ATTRIBUTE
;
83 // Genuine MacOS (X) errors identified by an OSStatus value.
84 // Don't even think of working with OSErr values; use OSStatus.
86 class MacOSError
: public CommonError
{
91 virtual OSStatus
osStatus() const;
92 virtual int unixError() const;
93 virtual const char *what () const throw ();
95 static void check(OSStatus status
) { if (status
!= errSecSuccess
) throwMe(status
); }
96 static void throwMe(int err
) __attribute__((noreturn
));
98 static MacOSError
make(int err
);
101 typedef std::set
<OSStatus
> MacOSErrorSet
;
105 // CoreFoundation errors.
106 // Since CF prefers not to tell us *why* something didn't work, this
107 // is not very useful - but it's better than faking it into one of the other
110 class CFError
: public CommonError
{
114 virtual OSStatus
osStatus() const;
115 virtual int unixError() const;
116 virtual const char *what () const throw ();
119 static void check(const T
&p
) { if (!p
) throwMe(); }
121 static void throwMe() __attribute__((noreturn
));
125 // Something that gets thrown when ModuleNexus creation fails
126 class ModuleNexusError
: public CommonError
{
128 ModuleNexusError() {}
131 virtual OSStatus
osStatus() const;
132 virtual int unixError() const;
133 static void throwMe() __attribute__((noreturn
));
136 } // end namespace Security
139 #endif //_H_UTILITIES_ERROR