diff options
author | Cameron Katri <me@cameronkatri.com> | 2022-05-25 22:16:52 -0400 |
---|---|---|
committer | Cameron Katri <me@cameronkatri.com> | 2022-05-25 22:16:52 -0400 |
commit | 35de91afe0ea4b09277b78c36e595ea6472643a4 (patch) | |
tree | c04c24aaefe9e2351d7148c99c25bcd29d94675e /append.c | |
parent | 4630d99a60f87144ecd9cb392c407a316f2da30f (diff) | |
download | trustcache-35de91afe0ea4b09277b78c36e595ea6472643a4.tar.gz trustcache-35de91afe0ea4b09277b78c36e595ea6472643a4.tar.zst trustcache-35de91afe0ea4b09277b78c36e595ea6472643a4.zip |
append: Allow specifying cdhash directly
Diffstat (limited to 'append.c')
-rw-r--r-- | append.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -25,6 +25,7 @@ * SUCH DAMAGE. */ +#include <ctype.h> #include <errno.h> #include <getopt.h> #include <stdbool.h> @@ -38,6 +39,14 @@ #include "compat.h" +static bool +ishexstring(const char *s) { + for (; *s != '\0'; s++) + if (!isxdigit(*s)) + return false; + return true; +} + int tcappend(int argc, char **argv) { @@ -83,7 +92,20 @@ tcappend(int argc, char **argv) }; for (int i = 1; i < argc; i++) { - append = cache_from_tree(argv[i], cache.version); + if (strlen(argv[i]) == 40 && ishexstring(argv[i])) { + append.num_entries = 1; + if (append.version == 0) { + append.hashes = calloc(1, sizeof(trust_cache_hash0)); + for (size_t j = 0; j < CS_CDHASH_LEN; j++) + sscanf(argv[i] + 2 * j, "%02hhx", &append.hashes[0][j]); + } else { + append.entries = calloc(1, sizeof(struct trust_cache_entry1)); + for (size_t j = 0; j < CS_CDHASH_LEN; j++) + sscanf(argv[i] + 2 * j, "%02hhx", &append.entries[0].cdhash[j]); + } + } else { + append = cache_from_tree(argv[i], cache.version); + } if (append.version == 0) { if ((cache.hashes = realloc(cache.hashes, sizeof(trust_cache_hash0) * (cache.num_entries + append.num_entries))) == NULL) |