diff options
| author | Cameron Katri <me@cameronkatri.com> | 2022-06-13 23:07:11 -0400 |
|---|---|---|
| committer | Cameron Katri <me@cameronkatri.com> | 2022-06-13 23:07:11 -0400 |
| commit | 6a5be2524f0d31a601687e8b5d09b9af92848dac (patch) | |
| tree | 5b972137814a4fb71eb29a1ee5520ca196d5b9f9 /trustcache.c | |
| parent | 5c02858affbcccd66f1f994c5a8cc475ea503591 (diff) | |
| download | trustcache-6a5be2524f0d31a601687e8b5d09b9af92848dac.tar.gz trustcache-6a5be2524f0d31a601687e8b5d09b9af92848dac.zip | |
Unify writing of trustcache to new function
Diffstat (limited to 'trustcache.c')
| -rw-r--r-- | trustcache.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/trustcache.c b/trustcache.c index adc594c..cb6c7b0 100644 --- a/trustcache.c +++ b/trustcache.c @@ -99,3 +99,29 @@ opentrustcache(const char *path) fclose(f); return cache; } + +int +writetrustcache(struct trust_cache cache, const char *path) +{ + FILE *f = NULL; + if ((f = fopen(path, "wb")) == NULL) { + fprintf(stderr, "%s: %s\n", path, strerror(errno)); + return -1; + } + + cache.version = htole32(cache.version); + cache.num_entries = htole32(cache.num_entries); + fwrite(&cache, sizeof(struct trust_cache) - sizeof(struct trust_cache_entry1*), 1, f); + cache.version = le32toh(cache.version); + cache.num_entries = le32toh(cache.num_entries); + + for (uint32_t i = 0; i < cache.num_entries; i++) { + if (cache.version == 0) + fwrite(&cache.hashes[i], sizeof(trust_cache_hash0), 1, f); + else if (cache.version == 1) + fwrite(&cache.entries[i], sizeof(struct trust_cache_entry1), 1, f); + } + + fclose(f); + return 0; +} |
