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
30namespace Security {
31namespace CodeSigning {
32
33
34//
35// We need a nothrow destructor
36//
37CSError::~CSError() throw ()
38{ }
39
40
41//
42// Create and throw various forms of CSError
43//
44void CSError::throwMe(OSStatus rc)
45{
46	throw CSError(rc);
47}
48
49void CSError::throwMe(OSStatus rc, CFDictionaryRef dict)
50{
51	throw CSError(rc, dict);
52}
53
54void 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//
63void 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//
72OSStatus 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
79OSStatus 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
89