2 * Created by Michael Brouwer on 2/14/12.
3 * Copyright 2012 Apple Inc. All Rights Reserved.
8 The functions provided in SOSTransport.h provide an interface to the
9 secure object syncing transport
12 #ifndef _SOSTRANSPORT_H_
13 #define _SOSTRANSPORT_H_
15 #include <corecrypto/ccsha1.h>
16 #include <CoreFoundation/CFData.h>
17 #include <CoreFoundation/CFError.h>
22 kSOSManifestUnsortedError
= 1,
23 kSOSManifestCreateError
= 2,
29 /* SOSTransport protocol (not opaque). */
30 typedef struct SOSTransport
*SOSTransportRef
;
33 bool (*send
)(SOSTransportRef transport
, CFDataRef message
);
36 /* Return the singleton cloud transport instance. */
37 SOSTransportRef
SOSTransportCopyCloudTransport(void);
39 #define SOSDigestSize ((size_t)CCSHA1_OUTPUT_SIZE)
41 #define SOSDigestVectorInit { .digest = NULL, .count = 0, .capacity = 0, .is_sorted = false }
43 struct SOSDigestVector
{
44 uint8_t (*digest
)[SOSDigestSize
];
50 /* SOSDigestVector. */
51 void SOSDigestVectorAppend(struct SOSDigestVector
*dv
, const uint8_t *digest
);
52 void SOSDigestVectorSort(struct SOSDigestVector
*dv
);
53 size_t SOSDigestVectorIndexOf(struct SOSDigestVector
*dv
, const uint8_t *digest
);
54 bool SOSDigestVectorContains(struct SOSDigestVector
*dv
, const uint8_t *digest
);
55 void SOSDigestVectorReplaceAtIndex(struct SOSDigestVector
*dv
, size_t ix
, const uint8_t *digest
);
56 void SOSDigestVectorFree(struct SOSDigestVector
*dv
);
58 typedef void (*SOSDigestVectorApplyFunc
)(void *context
, const uint8_t digest
[SOSDigestSize
]);
59 void SOSDigestVectorApply(struct SOSDigestVector
*dv
,
60 void *context
, SOSDigestVectorApplyFunc func
);
61 void SOSDigestVectorDiff(struct SOSDigestVector
*dv1
, struct SOSDigestVector
*dv2
,
62 struct SOSDigestVector
*dv1_2
, struct SOSDigestVector
*dv2_1
);
63 bool SOSDigestVectorPatch(struct SOSDigestVector
*base
, struct SOSDigestVector
*removals
,
64 struct SOSDigestVector
*additions
, struct SOSDigestVector
*dv
,
69 /* Forward declarations of SOS types. */
70 typedef struct __OpaqueSOSObjectID
*SOSObjectID
;
71 typedef struct __OpaqueSOSManifest
*SOSManifestRef
;
74 SOSManifestRef
SOSManifestCreateWithBytes(const uint8_t *bytes
, size_t len
,
76 SOSManifestRef
SOSManifestCreateWithData(CFDataRef data
, CFErrorRef
*error
);
77 void SOSManifestDispose(SOSManifestRef m
);
78 size_t SOSManifestGetSize(SOSManifestRef m
);
79 size_t SOSManifestGetCount(SOSManifestRef m
);
80 const uint8_t *SOSManifestGetBytePtr(SOSManifestRef m
);
81 CFDataRef
SOSManifestGetData(SOSManifestRef m
);
82 bool SOSManifestDiff(SOSManifestRef a
, SOSManifestRef b
,
83 SOSManifestRef
*a_minus_b
, SOSManifestRef
*b_minus_a
,
85 SOSManifestRef
SOSManifestCreateWithPatch(SOSManifestRef base
,
86 SOSManifestRef removals
,
87 SOSManifestRef additions
,
89 void SOSManifestForEach(SOSManifestRef m
, void(^block
)(CFDataRef e
));
91 CFStringRef
SOSManifestCopyDescription(SOSManifestRef m
);
94 SOSObjectRef
SOSManifestGetObject(SOSManifestRef m
, SOSObjectID k
);
95 void SOSManifestPutObject(SOSManifestRef m
, SOSObjectID k
, SOSObjectRef v
);
97 typedef SOSObjectRef(*SOSManifestGetF
)(void *get_ctx
, SOSObjectID k
);
98 SOSManifestRef
SOSManifestCreateSparse(void *get_ctx
, SOSManifestGetF get_f
);
103 #endif /* !_SOSTRANSPORT_H_ */