]> git.cameronkatri.com Git - trustcache.git/blob - trustcache.h
Fix compilation with -Wall -Wextra -Werror
[trustcache.git] / trustcache.h
1 #ifndef _TRUSTCACHE_H_
2 #define _TRUSTCACHE_H_
3
4 #include <stdbool.h>
5 #include <sys/types.h>
6
7 #if __APPLE__
8 # include <libkern/OSByteOrder.h>
9 # define htole32(x) OSSwapHostToLittleInt32(x)
10 # define le32toh(x) OSSwapLittleToHostInt32(x)
11 #elif __has_include(<endian.h>)
12 # include <endian.h>
13 #else
14 # include <sys/endian.h>
15 #endif
16
17 #include "machoparse/cs_blobs.h"
18 #include "uuid/uuid.h"
19
20 struct trust_cache_entry1 {
21 uint8_t cdhash[CS_CDHASH_LEN];
22 uint8_t hash_type;
23 uint8_t flags;
24 };
25
26 typedef uint8_t trust_cache_hash0[CS_CDHASH_LEN];
27
28 struct trust_cache {
29 uint32_t version;
30 uuid_t uuid;
31 uint32_t num_entries;
32 union {
33 struct trust_cache_entry1 *entries;
34 trust_cache_hash0 *hashes;
35 };
36 } __attribute__((__packed__));
37
38 // flags
39 #define CS_TRUST_CACHE_AMFID 0x1
40 #define CS_TRUST_CACHE_ANE 0x2
41
42 struct trust_cache opentrustcache(const char *path);
43 struct trust_cache cache_from_tree(const char *path, uint32_t version);
44
45 int tcinfo(int argc, char **argv);
46 int tccreate(int argc, char **argv);
47 int tcappend(int argc, char **argv);
48 int tcremove(int argc, char **argv);
49
50 int ent_cmp(const void * vp1, const void * vp2);
51 int hash_cmp(const void * vp1, const void * vp2);
52
53 void print_header(struct trust_cache cache);
54 void print_hash(uint8_t cdhash[CS_CDHASH_LEN], bool newline);
55 void print_entry(struct trust_cache_entry1 entry);
56 void print_entries(struct trust_cache cache);
57
58 #endif