#ifndef _SOSACCOUNT_H_
#define _SOSACCOUNT_H_
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>
#include "keychain/SecureObjectSync/SOSAccountPriv.h"
#include "keychain/SecureObjectSync/SOSCircle.h"
#include "keychain/SecureObjectSync/SOSFullPeerInfo.h"
#include <Security/SecureObjectSync/SOSCloudCircle.h>
#include <Security/SecureObjectSync/SOSCloudCircleInternal.h>
#include "keychain/SecureObjectSync/SOSTransportCircle.h"
#include "keychain/SecureObjectSync/SOSRing.h"
#include "keychain/SecureObjectSync/SOSRecoveryKeyBag.h"
#import "keychain/SecureObjectSync/SOSAccountTransaction.h"
#include <dispatch/dispatch.h>
@class SOSAccount;
__BEGIN_DECLS
#define RETIREMENT_FINALIZATION_SECONDS (24*60*60)
typedef void (^SOSAccountCircleMembershipChangeBlock)(SOSAccount* account,
SOSCircleRef new_circle,
CFSetRef added_peers, CFSetRef removed_peers,
CFSetRef added_applicants, CFSetRef removed_applicants);
CFTypeID SOSAccountGetTypeID(void);
SOSAccount* SOSAccountCreate(CFAllocatorRef allocator,
CFDictionaryRef gestalt,
SOSDataSourceFactoryRef factory);
SecKeyRef SOSAccountGetTrustedPublicCredential(SOSAccount* account, CFErrorRef* error);
SecKeyRef SOSAccountGetPrivateCredential(SOSAccount* account, CFErrorRef* error);
CFDataRef SOSAccountGetCachedPassword(SOSAccount* account, CFErrorRef* error);
void SOSAccountStashAccountKey(SOSAccount* account);
SecKeyRef SOSAccountCopyStashedUserPrivateKey(SOSAccount* account, CFErrorRef *error);
void SOSAccountSetParameters(SOSAccount* account, CFDataRef parameters);
void SOSAccountPurgePrivateCredential(SOSAccount* account);
void SOSAccountRestartPrivateCredentialTimer(SOSAccount* account);
bool SOSAccountTryUserCredentials(SOSAccount* account,
CFStringRef user_account, CFDataRef user_password,
CFErrorRef *error);
bool SOSAccountTryUserPrivateKey(SOSAccount* account, SecKeyRef user_private, CFErrorRef *error);
bool SOSAccountValidateAccountCredential(SOSAccount* account, SecKeyRef accountPrivateKey, CFErrorRef *error);
bool SOSAccountAssertStashedAccountCredential(SOSAccount* account, CFErrorRef *error);
bool SOSAccountAssertUserCredentials(SOSAccount* account,
CFStringRef user_account, CFDataRef user_password,
CFErrorRef *error);
bool SOSAccountRetryUserCredentials(SOSAccount* account);
void SOSAccountSetUnTrustedUserPublicKey(SOSAccount* account, SecKeyRef publicKey);
bool SOSAccountGenerationSignatureUpdate(SOSAccount* account, CFErrorRef *error);
bool SOSAccountUpdateCircle(SOSAccount* account, SOSCircleRef circle, CFErrorRef *error);
void SOSTransportEachMessage(SOSAccount* account, CFDictionaryRef updates, CFErrorRef *error);
CFStringRef SOSAccountGetSOSCCStatusString(SOSCCStatus status);
SOSCCStatus SOSAccountGetSOSCCStatusFromString(CFStringRef status);
bool SOSAccountJoinCircles(SOSAccountTransaction* aTxn, NSData* parentEvent, CFErrorRef* error);
bool SOSAccountJoinCirclesAfterRestore(SOSAccountTransaction* aTxn, NSData* parentEvent, CFErrorRef* error);
bool SOSAccountRemovePeersFromCircle(SOSAccount* account, CFArrayRef peers, NSData* parentEvent, CFErrorRef* error);
bool SOSAccountBail(SOSAccount* account, uint64_t limit_in_seconds, CFErrorRef* error);
bool SOSAccountAcceptApplicants(SOSAccount* account, CFArrayRef applicants, CFErrorRef* error);
bool SOSAccountRejectApplicants(SOSAccount* account, CFArrayRef applicants, CFErrorRef* error);
bool SOSValidateUserPublic(SOSAccount* account, CFErrorRef* error);
void SOSAccountForEachCirclePeerExceptMe(SOSAccount* account, void (^action)(SOSPeerInfoRef peer));
CFArrayRef SOSAccountCopyApplicants(SOSAccount* account, CFErrorRef *error);
CFArrayRef SOSAccountCopyGeneration(SOSAccount* account, CFErrorRef *error);
CFArrayRef SOSAccountCopyValidPeers(SOSAccount* account, CFErrorRef *error);
CFArrayRef SOSAccountCopyPeersToListenTo(SOSAccount* account, CFErrorRef *error);
CFArrayRef SOSAccountCopyNotValidPeers(SOSAccount* account, CFErrorRef *error);
CFArrayRef SOSAccountCopyRetired(SOSAccount* account, CFErrorRef *error);
CFArrayRef SOSAccountCopyViewUnaware(SOSAccount* account, CFErrorRef *error);
CFArrayRef SOSAccountCopyPeers(SOSAccount* account, CFErrorRef *error);
CFArrayRef SOSAccountCopyActivePeers(SOSAccount* account, CFErrorRef *error);
CFArrayRef CF_RETURNS_RETAINED SOSAccountCopyActiveValidPeers(SOSAccount* account, CFErrorRef *error);
CFArrayRef SOSAccountCopyConcurringPeers(SOSAccount* account, CFErrorRef *error);
bool SOSAccountIsAccountIdentity(SOSAccount* account, SOSPeerInfoRef peer_info, CFErrorRef *error);
enum DepartureReason SOSAccountGetLastDepartureReason(SOSAccount* account, CFErrorRef* error);
bool SOSAccountRemoveIncompleteiCloudIdentities(SOSAccount* account, SOSCircleRef circle, SecKeyRef privKey, CFErrorRef *error);
void SOSAccountAddChangeBlock(SOSAccount* a, SOSAccountCircleMembershipChangeBlock changeBlock);
void SOSAccountRemoveChangeBlock(SOSAccount* a, SOSAccountCircleMembershipChangeBlock changeBlock);
CFDictionaryRef SOSAccountCopyGestalt(SOSAccount* account);
CFDictionaryRef SOSAccountCopyV2Dictionary(SOSAccount* account);
void SOSAccountPendDisableViewSet(SOSAccount* account, CFSetRef disabledViews);
void SOSAccountUpdateOutOfSyncViews(SOSAccountTransaction* aTxn, CFSetRef viewsInSync);
void SOSAccountPeerGotInSync(SOSAccountTransaction* aTxn, CFStringRef peerID, CFSetRef views);
bool SOSAccountHandleParametersChange(SOSAccount* account, CFDataRef updates, CFErrorRef *error);
bool SOSAccountRequestSyncWithAllPeers(SOSAccountTransaction* txn, CFErrorRef *error);
CF_RETURNS_RETAINED CFMutableSetRef SOSAccountSyncWithPeers(SOSAccountTransaction* txn, CFSetRef peerIDs, CFErrorRef *error);
CFSetRef SOSAccountSyncWithPeersOverKVS(SOSAccountTransaction* txn, CFSetRef peers);
bool SOSAccountInflateTransports(SOSAccount* account, CFStringRef circleName, CFErrorRef *error);
void
SOSAccountTriggerSyncWithBackupPeer(CFStringRef peer);
bool SOSAccountSyncWithKVSPeerWithMessage(SOSAccountTransaction* txn, CFStringRef peerid, CFDataRef message, CFErrorRef *error);
CF_RETURNS_RETAINED CFSetRef SOSAccountProcessSyncWithPeers(SOSAccountTransaction* txn, CFSetRef peers, CFSetRef backupPeers, CFErrorRef *error);
CF_RETURNS_RETAINED CFSetRef SOSAccountCopyBackupPeersAndForceSync(SOSAccountTransaction* txn, CFErrorRef *error);
bool SOSAccountScanForRetired(SOSAccount* account, SOSCircleRef circle, CFErrorRef *error);
CF_RETURNS_RETAINED SOSCircleRef SOSAccountCloneCircleWithRetirement(SOSAccount* account, SOSCircleRef starting_circle, CFErrorRef *error);
bool SOSAccountIsBackupRingEmpty(SOSAccount* account, CFStringRef viewName);
bool SOSAccountNewBKSBForView(SOSAccount* account, CFStringRef viewName, CFErrorRef *error);
void SOSAccountProcessBackupRings(SOSAccount* account, CFErrorRef *error);
bool SOSAccountValidateBackupRingForView(SOSAccount* account, CFStringRef viewName, CFErrorRef *error);
bool SOSAccountSetBackupPublicKey(SOSAccountTransaction* aTxn, CFDataRef backupKey, CFErrorRef *error);
bool SOSAccountRemoveBackupPublickey(SOSAccountTransaction* aTxn, CFErrorRef *error);
bool SOSAccountBackupUpdateBackupPublicKey(SOSAccount *account, CFDataRef backupKey);
bool SOSAccountSetBSKBagForAllSlices(SOSAccount* account, CFDataRef backupSlice, bool setupV0Only, CFErrorRef *error);
CF_RETURNS_RETAINED SOSBackupSliceKeyBagRef SOSAccountBackupSliceKeyBagForView(SOSAccount* account, CFStringRef viewName, CFErrorRef* error);
bool SOSAccountRegisterRecoveryPublicKey(SOSAccountTransaction* txn, CFDataRef recovery_key, CFErrorRef *error);
CFDataRef SOSAccountCopyRecoveryPublicKey(SOSAccountTransaction* txn, CFErrorRef *error);
bool SOSAccountClearRecoveryPublicKey(SOSAccountTransaction* txn, CFDataRef recovery_key, CFErrorRef *error);
bool SOSAccountSetRecoveryKey(SOSAccount* account, CFDataRef pubData, CFErrorRef *error);
bool SOSAccountRemoveRecoveryKey(SOSAccount* account, CFErrorRef *error);
CFDataRef SOSAccountCopyRecoveryPublic(CFAllocatorRef allocator, SOSAccount* account, CFErrorRef *error);
bool SOSAccountRecoveryKeyIsInBackupAndCurrentInView(SOSAccount* account, CFStringRef viewname);
bool SOSAccountSetRecoveryKeyBagEntry(CFAllocatorRef allocator, SOSAccount* account, SOSRecoveryKeyBagRef rkbg, CFErrorRef *error);
SOSRecoveryKeyBagRef SOSAccountCopyRecoveryKeyBagEntry(CFAllocatorRef allocator, SOSAccount* account, CFErrorRef *error);
void SOSAccountEnsureRecoveryRing(SOSAccount* account);
dispatch_queue_t SOSAccountGetQueue(SOSAccount* account);
typedef bool (^SOSAccountSendBlock)(CFStringRef key, CFDataRef message, CFErrorRef *error);
CFStringRef SOSInterestListCopyDescription(CFArrayRef interests);
SOSPeerInfoRef SOSAccountCopyApplication(SOSAccount* account, CFErrorRef*);
CFDataRef SOSAccountCopyCircleJoiningBlob(SOSAccount* account, SOSPeerInfoRef applicant, CFErrorRef *error);
bool SOSAccountJoinWithCircleJoiningBlob(SOSAccount* account, CFDataRef joiningBlob, PiggyBackProtocolVersion version, CFErrorRef *error);
CFDataRef SOSAccountCopyInitialSyncData(SOSAccount* account, SOSInitialSyncFlags flags, CFErrorRef *error);
CFMutableSetRef SOSAccountCopyUnsyncedInitialViews(SOSAccount* account);
void SOSAccountLogState(SOSAccount* account);
void SOSAccountLogViewState(SOSAccount* account);
void SOSAccountConsiderLoggingEngineState(SOSAccountTransaction* txn);
CFBooleanRef SOSAccountPeersHaveViewsEnabled(SOSAccount* account, CFArrayRef viewNames, CFErrorRef *error);
void SOSAccountSetTestSerialNumber(SOSAccount* account, CFStringRef serial);
SOSViewResultCode SOSAccountVirtualV0Behavior(SOSAccount* account, SOSViewActionCode actionCode);
bool SOSAccountIsPeerRetired(SOSAccount* account, CFSetRef peers);
void SOSAccountNotifyOfChange(SOSAccount* account, SOSCircleRef oldCircle, SOSCircleRef newCircle);
bool SOSAccountMessageFromPeerIsPending(SOSAccountTransaction* txn, SOSPeerInfoRef peer, CFErrorRef *error);
bool SOSAccountSendToPeerIsPending(SOSAccountTransaction* txn, SOSPeerInfoRef peer, CFErrorRef *error);
void SOSAccountResetOTRNegotiationCoder(SOSAccount* account, CFStringRef peerid);
void SOSAccountTimerFiredSendNextMessage(SOSAccountTransaction* txn, NSString* peerid, NSString* accessGroup);
NSArray<NSDictionary *>* SOSAccountGetAllTLKs(void);
CF_RETURNS_RETAINED CFMutableArrayRef SOSAccountCopyiCloudIdentities(SOSAccount* account);
bool SOSAccountEvaluateKeysAndCircle(SOSAccountTransaction *txn, CFErrorRef *block_error);
__END_DECLS
#endif