7 #include "SOSAccountPriv.h"
9 #include <utilities/SecCFWrappers.h>
11 #import <Security/SecureObjectSync/SOSAccountTrust.h>
12 #import <Security/SecureObjectSync/SOSAccountTrustClassic.h>
15 // MARK: Generic Value manipulation
18 static inline bool SOSAccountEnsureExpansion(SOSAccount* account, CFErrorRef *error) {
20 if (!account.trust.expansion) {
21 account.trust.expansion = [NSMutableDictionary dictionary];
24 return SecAllocationError(((__bridge CFDictionaryRef)account.trust.expansion), error, CFSTR("Can't Alloc Account Expansion dictionary"));
27 bool SOSAccountClearValue(SOSAccount* account, CFStringRef key, CFErrorRef *error) {
28 bool success = SOSAccountEnsureExpansion(account, error);
33 [account.trust.expansion removeObjectForKey: (__bridge NSString* _Nonnull)(key)];
38 bool SOSAccountSetValue(SOSAccount* account, CFStringRef key, CFTypeRef value, CFErrorRef *error) {
39 if (value == NULL) return SOSAccountClearValue(account, key, error);
41 bool success = SOSAccountEnsureExpansion(account, error);
45 [account.trust.expansion setObject:(__bridge id _Nonnull)(value) forKey:(__bridge NSString* _Nonnull)(key)];
52 CFStringRef SOSAccountCopyUUID(SOSAccount* account) {
53 CFStringRef uuid = CFRetainSafe(asString(SOSAccountGetValue(account, kSOSAccountUUID, NULL), NULL));
55 CFUUIDRef newID = CFUUIDCreate(kCFAllocatorDefault);
56 uuid = CFUUIDCreateString(kCFAllocatorDefault, newID);
58 CFErrorRef setError = NULL;
59 if (!SOSAccountSetValue(account, kSOSAccountUUID, uuid, &setError)) {
60 secerror("Failed to set UUID: %@ (%@)", uuid, setError);
62 CFReleaseNull(setError);
68 void SOSAccountEnsureUUID(SOSAccount* account) {
69 CFStringRef uuid = SOSAccountCopyUUID(account);