2 * Copyright (c) 2017 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@
26 #import "keychain/ckks/CloudKitCategories.h"
28 @implementation CKOperationGroup (CKKS)
29 +(instancetype) CKKSGroupWithName:(NSString*)name {
30 CKOperationGroup* operationGroup = [[CKOperationGroup alloc] init];
31 operationGroup.expectedSendSize = CKOperationGroupTransferSizeKilobytes;
32 operationGroup.expectedReceiveSize = CKOperationGroupTransferSizeKilobytes;
33 operationGroup.name = name;
34 return operationGroup;
38 @implementation NSError (CKKS)
40 + (instancetype)errorWithDomain:(NSErrorDomain)domain code:(NSInteger)code description:(NSString*)description {
41 return [NSError errorWithDomain:domain code:code description:description underlying:nil];
44 + (instancetype)errorWithDomain:(NSErrorDomain)domain code:(NSInteger)code description:(NSString*)description underlying:(NSError*)underlying {
45 // Obj-C throws a fit if there's nulls in dictionaries, so we can't use a dictionary literal here.
46 // Use the null-assignment semantics of NSMutableDictionary to make a dictionary either with either, both, or neither key.
47 NSMutableDictionary* mut = [[NSMutableDictionary alloc] init];
48 mut[NSLocalizedDescriptionKey] = description;
49 mut[NSUnderlyingErrorKey] = underlying;
51 return [NSError errorWithDomain:domain code:code userInfo:mut];
54 -(bool) ckksIsCKErrorRecordChangedError {
55 NSDictionary<CKRecordID*,NSError*>* partialErrors = self.userInfo[CKPartialErrorsByItemIDKey];
56 if([self.domain isEqualToString:CKErrorDomain] && self.code == CKErrorPartialFailure && partialErrors) {
57 // Check if this error was "you're out of date"
59 for(NSError* error in partialErrors.objectEnumerator) {
60 if((![error.domain isEqualToString:CKErrorDomain]) || (error.code != CKErrorBatchRequestFailed && error.code != CKErrorServerRecordChanged && error.code != CKErrorUnknownItem)) {
61 // There's an error in there that isn't CKErrorServerRecordChanged, CKErrorBatchRequestFailed, or CKErrorUnknownItem. Don't handle nicely...
73 @implementation CKAccountInfo (CKKS)
74 // Ugly, and might break if CloudKit changes how they print objects. Sorry, CloudKit!
75 - (NSString*)description {
76 NSString* ckprop = [self CKPropertiesDescription];
77 NSString* description = [NSString stringWithFormat: @"<CKAccountInfo: %@>", ckprop];