commit 14bbe0dc3793eb4b72d27759bd83602c2c04d54d from: Omar Polo date: Fri Jul 12 19:22:45 2024 UTC add got_hash_digest_to_str commit - a3dc7ed231aec149a7f09125e4cd2d37480df44d commit + 14bbe0dc3793eb4b72d27759bd83602c2c04d54d blob - 3142e9056bb96d9e90120d4a1b1a6bf9e09e937a blob + d26b8fd7cb44552d1150e2c3074683021ccdb304 --- lib/got_lib_hash.h +++ lib/got_lib_hash.h @@ -18,11 +18,14 @@ #define GOT_SHA256_STRING_ZERO "0000000000000000000000000000000000000000000000000000000000000000" #define GOT_HASH_DIGEST_MAXLEN SHA256_DIGEST_LENGTH +#define GOT_HASH_DIGEST_STRING_MAXLEN SHA256_DIGEST_STRING_LENGTH int got_parse_xdigit(uint8_t *, const char *); char *got_sha1_digest_to_str(const uint8_t *, char *, size_t); char *got_sha256_digest_to_str(const uint8_t *, char *, size_t); +char *got_hash_digest_to_str(const uint8_t *, char *, size_t, + enum got_hash_algorithm); int got_parse_hash_digest(uint8_t *, const char *, enum got_hash_algorithm); blob - daa3516614f132aef1e370991d07c4c3699dc955 blob + c604f275f01dbbef64fe927f5c9abd75a32dd94d --- lib/hash.c +++ lib/hash.c @@ -138,6 +138,21 @@ got_sha256_digest_to_str(const uint8_t *digest, char * return digest_to_str(digest, SHA256_DIGEST_LENGTH, buf); } +char * +got_hash_digest_to_str(const uint8_t *digest, char *buf, size_t size, + enum got_hash_algorithm algo) +{ + switch (algo) { + case GOT_HASH_SHA1: + return got_sha1_digest_to_str(digest, buf, size); + case GOT_HASH_SHA256: + return got_sha256_digest_to_str(digest, buf, size); + default: + abort(); + return NULL; + } +} + int got_parse_hash_digest(uint8_t *digest, const char *line, enum got_hash_algorithm algo) blob - aba3538bb59276a61594f385c2b5c61f44fde700 blob + 74715d03c7a47ec8612b69c2d492e47ffa86062e --- lib/pack.c +++ lib/pack.c @@ -692,11 +692,12 @@ got_packidx_match_id_str_prefix(struct got_object_id_q i = be32toh(packidx->hdr.fanout_table[id0 - 1]); oid = packidx->hdr.sorted_ids + i * digest_len; while (i < totobj && oid[0] == id0) { - char id_str[SHA1_DIGEST_STRING_LENGTH]; + char id_str[GOT_HASH_DIGEST_STRING_MAXLEN]; struct got_object_qid *qid; int cmp; - if (!got_sha1_digest_to_str(oid, id_str, sizeof(id_str))) + if (!got_hash_digest_to_str(oid, id_str, sizeof(id_str), + packidx->algo)) return got_error(GOT_ERR_NO_SPACE); cmp = strncmp(id_str, id_str_prefix, prefix_len);