2 * Copyright (c) 2000-2004,2006,2011,2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
28 #include <security_cdsa_utilities/cssmerrors.h>
29 #include <security_utilities/mach++.h>
30 #include <Security/cssmapple.h>
31 #include <Security/SecBase.h>
36 CssmError::CssmError(CSSM_RETURN err
) : error(err
)
38 SECURITY_EXCEPTION_THROW_CSSM(this, err
);
42 const char *CssmError::what() const throw ()
44 return "CSSM exception";
48 OSStatus
CssmError::osStatus() const
50 if (error
== CSSM_ERRCODE_INVALID_POINTER
)
59 int CssmError::unixError() const
61 OSStatus err
= osStatus();
63 // embedded UNIX errno values are returned verbatim
64 if (err
>= errSecErrnoBase
&& err
<= errSecErrnoLimit
)
65 return err
- errSecErrnoBase
;
67 // re-map certain CSSM errors
69 case CSSM_ERRCODE_MEMORY_ERROR
:
71 case CSSMERR_APPLEDL_DISK_FULL
:
73 case CSSMERR_APPLEDL_QUOTA_EXCEEDED
:
75 case CSSMERR_APPLEDL_FILE_TOO_BIG
:
78 // cannot map this to errno space
84 void CssmError::throwMe(CSSM_RETURN err
)
90 CSSM_RETURN
CssmError::merge(CSSM_RETURN error
, CSSM_RETURN base
)
92 if (0 < error
&& error
< CSSM_ERRORCODE_COMMON_EXTENT
) {
100 // Get a CSSM_RETURN from a CommonError
102 CSSM_RETURN
CssmError::cssmError(const CommonError
&error
, CSSM_RETURN base
)
104 if (const CssmError
*cssm
= dynamic_cast<const CssmError
*>(&error
)) {
105 return cssmError(cssm
->error
, base
);
106 } else if (const MachPlusPlus::Error
*mach
= dynamic_cast<const MachPlusPlus::Error
*>(&error
)) {
107 switch (mach
->error
) {
108 case BOOTSTRAP_UNKNOWN_SERVICE
:
109 case MIG_SERVER_DIED
:
110 return CSSM_ERRCODE_SERVICE_NOT_AVAILABLE
;
112 return CSSM_ERRCODE_INTERNAL_ERROR
;
115 return error
.osStatus();
119 CSSM_RETURN
CssmError::cssmError(CSSM_RETURN error
, CSSM_RETURN base
)
121 if (0 < error
&& error
< CSSM_ERRORCODE_COMMON_EXTENT
) {
129 } // namespace Security