]> git.saurik.com Git - apple/security.git/blob - Keychain/KCUtilities.h
Security-54.1.tar.gz
[apple/security.git] / Keychain / KCUtilities.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18 #ifndef _SECURITY_KCUTILITIES_H_
19 #define _SECURITY_KCUTILITIES_H_
20
21 #include <Security/SecKeychainItem.h>
22 #include <Security/utilities.h>
23 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
24 #include <memory>
25
26 namespace Security
27 {
28
29 OSStatus GetKeychainErrFromCSSMErr(OSStatus cssmError);
30
31 //
32 // Helpers for memory pointer validation
33 //
34 template <class T>
35 inline T &RequiredParam(T *ptr,OSStatus err = paramErr)
36 {
37 if (ptr == NULL)
38 MacOSError::throwMe(err);
39 return *ptr;
40 }
41
42 class StKCAttribute
43 {
44 public:
45 StKCAttribute( SecKeychainAttribute* attr );
46 virtual ~StKCAttribute( void );
47 private:
48 SecKeychainAttribute* fAttr;
49 };
50
51 // Class for cleaning up a KCItemRef when finished with it
52 // if an error occurs at any time when dealing with the item.
53 //
54 class StKCItem
55 {
56 public:
57 StKCItem( SecKeychainItemRef* item, OSStatus* result );
58 virtual ~StKCItem( void );
59 private:
60 SecKeychainItemRef* fItem;
61 OSStatus* fResult;
62 };
63
64 } // end namespace Security
65
66 #endif // !_SECURITY_KCUTILITIES_H_