]>
git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/cs.h
d7957fc9e4994e0e4246a0c70619040d12773513
2 * Copyright (c) 2006 Apple Computer, 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@
25 // cs.h - code signing core header
31 #include <Security/CodeSigning.h>
32 #include <Security/SecCodeSigner.h>
33 #include <Security/SecBasePriv.h>
34 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
35 #include <security_utilities/globalizer.h>
36 #include <security_utilities/seccfobject.h>
37 #include <security_utilities/cfclass.h>
38 #include <security_utilities/errors.h>
39 #include <security_utilities/cfutilities.h>
43 namespace CodeSigning
{
47 // API per-thread globals
50 SecCSFlags flags
; // flags of pending API call
64 ThreadNexus
<PerThread
> perThread
;
66 SecCSFlags
&flags() { return perThread().flags
; }
69 extern ModuleNexus
<CFObjects
> gCFObjects
;
71 static inline SecCSFlags
apiFlags() { return gCFObjects().flags(); }
75 // Code Signing API brackets
82 catch (const UnixError &err) { \
83 switch (err.error) { \
84 case ENOEXEC: return errSecCSBadObjectFormat; \
85 default: return err.osStatus(); \
87 catch (const MacOSError &err) { return err.osStatus(); } \
88 catch (const CommonError &err) { return SecKeychainErrFromOSStatus(err.osStatus()); } \
89 catch (const std::bad_alloc &) { return memFullErr; } \
90 catch (...) { return internalComponentErr; } \
93 #define END_CSAPI_ERRORS \
95 catch (const CSError &err) { return err.cfError(errors); } \
96 catch (const UnixError &err) { \
97 switch (err.error) { \
98 case ENOEXEC: return CSError::cfError(errors, errSecCSBadObjectFormat); \
99 default: return CSError::cfError(errors, err.osStatus()); \
101 catch (const MacOSError &err) { return CSError::cfError(errors, err.osStatus()); } \
102 catch (const CommonError &err) { return CSError::cfError(errors, SecKeychainErrFromOSStatus(err.osStatus())); } \
103 catch (const std::bad_alloc &) { return CSError::cfError(errors, memFullErr); } \
104 catch (...) { return CSError::cfError(errors, internalComponentErr); } \
107 #define END_CSAPI1(bad) } catch (...) { return bad; }
111 // A version of Required
114 static inline T
&Required(T
*ptr
)
117 MacOSError::throwMe(errSecCSObjectRequired
);
121 static inline void Required(const void *ptr
)
124 MacOSError::throwMe(errSecCSObjectRequired
);
129 // Check flags against a validity mask
131 static inline void checkFlags(SecCSFlags flags
, SecCSFlags acceptable
= 0)
133 if (flags
& ~acceptable
)
134 MacOSError::throwMe(errSecCSInvalidFlags
);
135 gCFObjects().flags() = flags
;