]> git.saurik.com Git - apple/security.git/blame - OSX/sec/SOSCircle/SecureObjectSync/SOSDigestVector.h
Security-57740.51.3.tar.gz
[apple/security.git] / OSX / sec / SOSCircle / SecureObjectSync / SOSDigestVector.h
CommitLineData
d8f41ccd
A
1/*
2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25/*!
26 @header SOSDigestVector.h
27 The functions provided in SOSDigestVector.h provide an interface doing
28 cheap appending, lazy sorting and delta math on sorted arrays of same
29 sized objects.
30 */
31
32#ifndef _SEC_SOSDIGESTVECTOR_H_
33#define _SEC_SOSDIGESTVECTOR_H_
34
35#include <corecrypto/ccsha1.h>
36#include <CoreFoundation/CFError.h>
fa7225c8 37#include <sys/types.h>
d8f41ccd
A
38
39__BEGIN_DECLS
40
41enum {
42 kSOSDigestVectorRemovalsLeftError = 1,
43 kSOSDigestVectorUnorderedAddError = 2,
44};
45
46extern CFStringRef kSOSDigestVectorErrorDomain;
47
48#define SOSDigestSize ((size_t)CCSHA1_OUTPUT_SIZE)
49
50#define SOSDigestVectorInit { .digest = NULL, .count = 0, .capacity = 0, .unsorted = false }
51
fa7225c8
A
52typedef uint8_t (*SOSDigestVectorDigestPtr)[SOSDigestSize];
53
d8f41ccd
A
54struct SOSDigestVector {
55 uint8_t (*digest)[SOSDigestSize];
56 size_t count;
57 size_t capacity;
58 bool unsorted;
59};
60
61typedef void (^SOSDigestVectorApplyBlock)(const uint8_t digest[SOSDigestSize], bool *stop);
62
63/* SOSDigestVector. */
64void SOSDigestVectorAppend(struct SOSDigestVector *dv, const uint8_t *digest);
65void SOSDigestVectorAppendMultipleOrdered(struct SOSDigestVector *dv, size_t count,
66 const uint8_t *digests);
67void SOSDigestVectorSort(struct SOSDigestVector *dv);
68void SOSDigestVectorSwap(struct SOSDigestVector *dva, struct SOSDigestVector *dvb);
69size_t SOSDigestVectorIndexOf(struct SOSDigestVector *dv, const uint8_t *digest);
70size_t SOSDigestVectorIndexOfSorted(const struct SOSDigestVector *dv, const uint8_t *digest);
71bool SOSDigestVectorContains(struct SOSDigestVector *dv, const uint8_t *digest);
72bool SOSDigestVectorContainsSorted(const struct SOSDigestVector *dv, const uint8_t *digest);
d8f41ccd
A
73void SOSDigestVectorFree(struct SOSDigestVector *dv);
74
75void SOSDigestVectorApply(struct SOSDigestVector *dv, SOSDigestVectorApplyBlock with);
76void SOSDigestVectorApplySorted(const struct SOSDigestVector *dv, SOSDigestVectorApplyBlock with);
77void SOSDigestVectorIntersectSorted(const struct SOSDigestVector *dv1, const struct SOSDigestVector *dv2,
78 struct SOSDigestVector *dvintersect);
79void SOSDigestVectorUnionSorted(const struct SOSDigestVector *dv1, const struct SOSDigestVector *dv2,
80 struct SOSDigestVector *dvunion);
81void SOSDigestVectorUniqueSorted(struct SOSDigestVector *dv);
82
83void SOSDigestVectorDiffSorted(const struct SOSDigestVector *dv1, const struct SOSDigestVector *dv2,
84 struct SOSDigestVector *dv1_2, struct SOSDigestVector *dv2_1);
85void SOSDigestVectorDiff(struct SOSDigestVector *dv1, struct SOSDigestVector *dv2,
86 struct SOSDigestVector *dv1_2, struct SOSDigestVector *dv2_1);
87void SOSDigestVectorComplementSorted(const struct SOSDigestVector *dvA, const struct SOSDigestVector *dvB,
88 struct SOSDigestVector *dvcomplement);
89bool SOSDigestVectorPatchSorted(const struct SOSDigestVector *base, const struct SOSDigestVector *removals,
90 const struct SOSDigestVector *additions, struct SOSDigestVector *dv,
91 CFErrorRef *error);
92bool SOSDigestVectorPatch(struct SOSDigestVector *base, struct SOSDigestVector *removals,
93 struct SOSDigestVector *additions, struct SOSDigestVector *dv,
94 CFErrorRef *error);
95
96__END_DECLS
97
98#endif /* !_SEC_SOSDIGESTVECTOR_H_ */