]> git.saurik.com Git - apple/security.git/blob - Keychain/KCUtilities.cpp
Security-179.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 case CSSM_ERRCODE_NO_USER_INTERACTION:
43 return errSecInteractionNotAllowed;
44 case CSSM_ERRCODE_OS_ACCESS_DENIED:
45 return wrPermErr;
46 default:
47 return cssmError;
48 }
49 }
50 else
51 {
52 switch (cssmError)
53 {
54 // DL SPECIFIC ERROR CODES
55 case CSSMERR_DL_OS_ACCESS_DENIED:
56 return wrPermErr;
57 case CSSMERR_DL_RECORD_NOT_FOUND:
58 return errSecItemNotFound;
59 case CSSMERR_DL_INVALID_UNIQUE_INDEX_DATA:
60 return errSecDuplicateItem;
61 case CSSMERR_DL_DATABASE_CORRUPT:
62 return errSecInvalidKeychain;
63 case CSSMERR_DL_DATASTORE_DOESNOT_EXIST:
64 return errSecNoSuchKeychain;
65 case CSSMERR_DL_DATASTORE_ALREADY_EXISTS:
66 return errSecDuplicateKeychain;
67 case CSSMERR_DL_INVALID_FIELD_NAME:
68 return errSecNoSuchAttr;
69 default:
70 return cssmError;
71 }
72 }
73 }
74
75 StKCAttribute::StKCAttribute( SecKeychainAttribute* inPtr ) :
76 fAttr( inPtr )
77 {
78 }
79
80 StKCAttribute::~StKCAttribute( )
81 {
82 delete fAttr;
83 }
84
85 StKCItem::StKCItem( SecKeychainItemRef* inItem, OSStatus* result ) :
86 fItem( inItem ),
87 fResult( result )
88 {
89 }
90
91 StKCItem::~StKCItem( )
92 {
93 // if an error occured and the item is valid, release the item
94 //
95 if ( *fResult != noErr && *fItem != NULL )
96 CFRelease(*fItem );
97 }
98
99 } // end namespace Security