]> git.saurik.com Git - apple/security.git/blob - Keychain/KCUtilities.cpp
Security-28.tar.gz
[apple/security.git] / Keychain / KCUtilities.cpp
1 /*
2 * Copyright (c) 2000-2001 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
19 #ifdef __MWERKS__
20 #define _KC_UTILITIES
21 #endif
22
23 #include <Security/KCUtilities.h>
24 #include <Security/cssmerrno.h>
25
26 namespace Security
27 {
28
29 OSStatus GetKeychainErrFromCSSMErr( OSStatus cssmError )
30 {
31 if (CSSM_ERR_IS_CONVERTIBLE(cssmError))
32 {
33 switch (CSSM_ERRCODE(cssmError))
34 {
35 // CONVERTIBLE ERROR CODES.
36 case CSSM_ERRCODE_SERVICE_NOT_AVAILABLE:
37 return errSecNotAvailable;
38 case CSSM_ERRCODE_USER_CANCELED:
39 return userCanceledErr;
40 case CSSM_ERRCODE_OPERATION_AUTH_DENIED:
41 return errSecAuthFailed;
42 default:
43 return cssmError;
44 }
45 }
46 else
47 {
48 switch (cssmError)
49 {
50 // DL SPECIFIC ERROR CODES
51 case CSSMERR_DL_RECORD_NOT_FOUND:
52 return errSecItemNotFound;
53 case CSSMERR_DL_INVALID_UNIQUE_INDEX_DATA:
54 return errSecDuplicateItem;
55 case CSSMERR_DL_DATABASE_CORRUPT:
56 return errSecInvalidKeychain;
57 case CSSMERR_DL_DATASTORE_DOESNOT_EXIST:
58 return errSecNoSuchKeychain;
59 case CSSMERR_DL_DATASTORE_ALREADY_EXISTS:
60 return errSecDuplicateKeychain;
61 case CSSMERR_DL_INVALID_FIELD_NAME:
62 return errSecNoSuchAttr;
63 default:
64 return cssmError;
65 }
66 }
67 }
68
69 StKCAttribute::StKCAttribute( SecKeychainAttribute* inPtr ) :
70 fAttr( inPtr )
71 {
72 }
73
74 StKCAttribute::~StKCAttribute( )
75 {
76 delete fAttr;
77 }
78
79 StKCItem::StKCItem( SecKeychainItemRef* inItem, OSStatus* result ) :
80 fItem( inItem ),
81 fResult( result )
82 {
83 }
84
85 StKCItem::~StKCItem( )
86 {
87 // if an error occured and the item is valid, release the item
88 //
89 if ( *fResult != noErr && *fItem != NULL )
90 ::SecKeychainItemRelease(*fItem ); // %%% rjp was KCItemRelease(fitem);
91 }
92
93 } // end namespace Security