commit 87a4b05fb8b2ad9ea533436eaf47108b48ba66cf from: Omar Polo date: Sat Feb 04 14:00:31 2023 UTC add got_parse_hash_digest helper it abstracts over the hash type, allowing to just propagate the hash type as argument. commit - 89720b41149f2c392d7641dcf30b1259d3f71af6 commit + 87a4b05fb8b2ad9ea533436eaf47108b48ba66cf blob - faf9e8a717096264c717436f464e9b6cbf22d64e blob + 5518a1cb6ab9c8c2bceae1e6f0032960bd410327 --- lib/got_lib_hash.h +++ lib/got_lib_hash.h @@ -24,3 +24,5 @@ char *got_sha1_digest_to_str(const uint8_t *, char *, int got_parse_sha256_digest(uint8_t *, const char *); char *got_sha256_digest_to_str(const uint8_t *, char *, size_t); + +int got_parse_hash_digest(uint8_t *, const char *, int, size_t *); blob - 64485ff6dfa3d6b53ae14ed4929b4464fff2160f blob + 7e3535126160cf2e341e9c48a9d1381337189e85 --- lib/hash.c +++ lib/hash.c @@ -15,6 +15,8 @@ */ #include +#include + #include #include #include @@ -24,6 +26,8 @@ #include "got_lib_hash.h" +#include "got_object.h" + int got_parse_xdigit(uint8_t *val, const char *hex) { @@ -126,3 +130,19 @@ got_sha256_digest_to_str(const uint8_t *digest, char * return buf; } + +int +got_parse_hash_digest(uint8_t *digest, const char *line, int algo, size_t *len) +{ + if (algo == GOT_HASH_SHA256) { + if (len) + *len = SHA256_DIGEST_STRING_LENGTH; + return got_parse_sha256_digest(digest, line); + } else if (algo == GOT_HASH_SHA1) { + if (len) + *len = SHA1_DIGEST_STRING_LENGTH; + return got_parse_sha1_digest(digest, line); + } + + return 0; +}