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> 37 38__BEGIN_DECLS 39 40enum { 41 kSOSDigestVectorRemovalsLeftError = 1, 42 kSOSDigestVectorUnorderedAddError = 2, 43}; 44 45extern CFStringRef kSOSDigestVectorErrorDomain; 46 47#define SOSDigestSize ((size_t)CCSHA1_OUTPUT_SIZE) 48 49#define SOSDigestVectorInit { .digest = NULL, .count = 0, .capacity = 0, .unsorted = false } 50 51struct SOSDigestVector { 52 uint8_t (*digest)[SOSDigestSize]; 53 size_t count; 54 size_t capacity; 55 bool unsorted; 56}; 57 58typedef void (^SOSDigestVectorApplyBlock)(const uint8_t digest[SOSDigestSize], bool *stop); 59 60/* SOSDigestVector. */ 61void SOSDigestVectorAppend(struct SOSDigestVector *dv, const uint8_t *digest); 62void SOSDigestVectorAppendMultipleOrdered(struct SOSDigestVector *dv, size_t count, 63 const uint8_t *digests); 64void SOSDigestVectorSort(struct SOSDigestVector *dv); 65void SOSDigestVectorSwap(struct SOSDigestVector *dva, struct SOSDigestVector *dvb); 66size_t SOSDigestVectorIndexOf(struct SOSDigestVector *dv, const uint8_t *digest); 67size_t SOSDigestVectorIndexOfSorted(const struct SOSDigestVector *dv, const uint8_t *digest); 68bool SOSDigestVectorContains(struct SOSDigestVector *dv, const uint8_t *digest); 69bool SOSDigestVectorContainsSorted(const struct SOSDigestVector *dv, const uint8_t *digest); 70void SOSDigestVectorReplaceAtIndex(struct SOSDigestVector *dv, size_t ix, const uint8_t *digest); 71void SOSDigestVectorFree(struct SOSDigestVector *dv); 72 73void SOSDigestVectorApply(struct SOSDigestVector *dv, SOSDigestVectorApplyBlock with); 74void SOSDigestVectorApplySorted(const struct SOSDigestVector *dv, SOSDigestVectorApplyBlock with); 75void SOSDigestVectorIntersectSorted(const struct SOSDigestVector *dv1, const struct SOSDigestVector *dv2, 76 struct SOSDigestVector *dvintersect); 77void SOSDigestVectorUnionSorted(const struct SOSDigestVector *dv1, const struct SOSDigestVector *dv2, 78 struct SOSDigestVector *dvunion); 79void SOSDigestVectorUniqueSorted(struct SOSDigestVector *dv); 80 81void SOSDigestVectorDiffSorted(const struct SOSDigestVector *dv1, const struct SOSDigestVector *dv2, 82 struct SOSDigestVector *dv1_2, struct SOSDigestVector *dv2_1); 83void SOSDigestVectorDiff(struct SOSDigestVector *dv1, struct SOSDigestVector *dv2, 84 struct SOSDigestVector *dv1_2, struct SOSDigestVector *dv2_1); 85void SOSDigestVectorComplementSorted(const struct SOSDigestVector *dvA, const struct SOSDigestVector *dvB, 86 struct SOSDigestVector *dvcomplement); 87bool SOSDigestVectorPatchSorted(const struct SOSDigestVector *base, const struct SOSDigestVector *removals, 88 const struct SOSDigestVector *additions, struct SOSDigestVector *dv, 89 CFErrorRef *error); 90bool SOSDigestVectorPatch(struct SOSDigestVector *base, struct SOSDigestVector *removals, 91 struct SOSDigestVector *additions, struct SOSDigestVector *dv, 92 CFErrorRef *error); 93 94__END_DECLS 95 96#endif /* !_SEC_SOSDIGESTVECTOR_H_ */ 97