]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/lib/cserror.cpp
Security-58286.260.20.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / lib / cserror.cpp
1 /*
2 * Copyright (c) 2007,2011 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 //
25 // cserror.h - extended-diagnostics Code Signing errors
26 //
27 #include "cs.h"
28 #include <security_utilities/cfmunge.h>
29
30 namespace Security {
31 namespace CodeSigning {
32
33
34 //
35 // We need a nothrow destructor
36 //
37 CSError::~CSError() throw ()
38 { }
39
40
41 //
42 // Create and throw various forms of CSError
43 //
44 void CSError::throwMe(OSStatus rc)
45 {
46 throw CSError(rc);
47 }
48
49 void CSError::throwMe(OSStatus rc, CFDictionaryRef dict)
50 {
51 throw CSError(rc, dict);
52 }
53
54 void CSError::throwMe(OSStatus rc, CFStringRef key, CFTypeRef value)
55 {
56 throw CSError(rc, cfmake<CFDictionaryRef>("{%O=%O}", key, value));
57 }
58
59
60 //
61 // Add a key/value pair to the dictionary
62 //
63 void CSError::augment(CFStringRef key, CFTypeRef value)
64 {
65 mInfoDict.take(cfmake<CFDictionaryRef>("{+%O,%O=%O}", mInfoDict.get(), key, value));
66 }
67
68
69 //
70 // Convert exception-carried error information to CFError form
71 //
72 OSStatus CSError::cfError(CFErrorRef *errors) const
73 {
74 if (errors) // errors argument was specified
75 *errors = CFErrorCreate(NULL, kCFErrorDomainOSStatus, this->osStatus(), this->infoDict());
76 return this->osStatus();
77 }
78
79 OSStatus CSError::cfError(CFErrorRef *errors, OSStatus rc)
80 {
81 if (errors)
82 *errors = CFErrorCreate(NULL, kCFErrorDomainOSStatus, rc, NULL);
83 return rc;
84 }
85
86
87 } // CodeSigning
88 } // Security