2 * Copyright (c) 2012-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@
25 #ifndef _SOSINTERNAL_H_
26 #define _SOSINTERNAL_H_
28 #include <CoreFoundation/CoreFoundation.h>
30 #include <Security/SecKey.h>
32 #include <SecureObjectSync/SOSCloudCircle.h>
34 #include <utilities/SecCFWrappers.h>
39 // Public errors are first (See SOSCloudCircle)
41 kSOSErrorFirstPrivateError
= 1024,
43 kSOSErrorAllocationFailure
= 1024,
44 kSOSErrorEncodeFailure
= 1025,
45 kSOSErrorNameMismatch
= 1026,
46 kSOSErrorSendFailure
= 1027,
47 kSOSErrorProcessingFailure
= 1028,
48 kSOSErrorDecodeFailure
= 1029,
50 kSOSErrorAlreadyPeer
= 1030,
51 kSOSErrorNotApplicant
= 1031,
52 kSOSErrorPeerNotFound
= 1032,
54 kSOSErrorNoKey
= 1033,
55 kSOSErrorBadKey
= 1034,
56 kSOSErrorBadFormat
= 1035,
57 kSOSErrorNoCircleName
= 1036,
58 kSOSErrorNoCircle
= 1037,
59 kSOSErrorBadSignature
= 1038,
60 kSOSErrorReplay
= 1039,
62 kSOSErrorUnexpectedType
= 1040,
64 kSOSErrorUnsupported
= 1041
67 // Returns false unless errorCode is 0.
68 bool SOSErrorCreate(CFIndex errorCode
, CFErrorRef
*error
, CFDictionaryRef formatOptions
, CFStringRef descriptionString
, ...);
70 bool SOSCreateError(CFIndex errorCode
, CFStringRef descriptionString
, CFErrorRef previousError
, CFErrorRef
*newError
);
72 bool SOSCreateErrorWithFormat(CFIndex errorCode
, CFErrorRef previousError
, CFErrorRef
*newError
,
73 CFDictionaryRef formatOptions
, CFStringRef formatString
, ...)
74 CF_FORMAT_FUNCTION(5,6);
76 bool SOSCreateErrorWithFormatAndArguments(CFIndex errorCode
, CFErrorRef previousError
, CFErrorRef
*newError
,
77 CFDictionaryRef formatOptions
, CFStringRef formatString
, va_list args
)
78 CF_FORMAT_FUNCTION(5,0);
81 static inline bool isSOSErrorCoded(CFErrorRef error
, CFIndex sosErrorCode
) {
82 return error
&& CFErrorGetCode(error
) == sosErrorCode
&& CFEqualSafe(CFErrorGetDomain(error
), kSOSErrorDomain
);
89 OSStatus
GenerateECPair(int keySize
, SecKeyRef
* public, SecKeyRef
*full
);
90 OSStatus
GeneratePermanentECPair(int keySize
, SecKeyRef
* public, SecKeyRef
*full
);
92 CFStringRef
SOSChangesCopyDescription(CFDictionaryRef changes
, bool is_sender
);
94 CFStringRef
SOSCopyIDOfKey(SecKeyRef key
, CFErrorRef
*error
);
97 // Der encoding accumulation
99 static inline bool accumulate_size(size_t *accumulator
, size_t size
) {
100 *accumulator
+= size
;