From 35de91afe0ea4b09277b78c36e595ea6472643a4 Mon Sep 17 00:00:00 2001 From: Cameron Katri Date: Wed, 25 May 2022 22:16:52 -0400 Subject: append: Allow specifying cdhash directly --- append.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'append.c') diff --git a/append.c b/append.c index cf8dc83..764ab3f 100644 --- a/append.c +++ b/append.c @@ -25,6 +25,7 @@ * SUCH DAMAGE. */ +#include #include #include #include @@ -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) -- cgit v1.2.3