commit 020f73dba5df9e319726af7526dbb3b478d52b76 from: Omar Polo date: Thu Jul 11 13:33:04 2024 UTC add got_hash_digest{,_string}_length() These will be very much useful in the near future. commit - be12ea2c3492ea9c1292c0c73e59723ead326d6d commit + 020f73dba5df9e319726af7526dbb3b478d52b76 blob - 88c77f6eb9da4d589aefd2ed3e9539327d379e53 blob + 3142e9056bb96d9e90120d4a1b1a6bf9e09e937a --- lib/got_lib_hash.h +++ lib/got_lib_hash.h @@ -36,6 +36,32 @@ char *got_object_id_hex(struct got_object_id *, char * int got_parse_object_id(struct got_object_id *, const char *, enum got_hash_algorithm); +static inline int +got_hash_digest_length(enum got_hash_algorithm algo) +{ + switch (algo) { + case GOT_HASH_SHA1: + return SHA1_DIGEST_LENGTH; + case GOT_HASH_SHA256: + return SHA256_DIGEST_LENGTH; + default: + return 0; + } +} + +static inline int +got_hash_digest_string_length(enum got_hash_algorithm algo) +{ + switch (algo) { + case GOT_HASH_SHA1: + return SHA1_DIGEST_STRING_LENGTH; + case GOT_HASH_SHA256: + return SHA256_DIGEST_STRING_LENGTH; + default: + return 0; + } +} + struct got_hash { SHA1_CTX sha1_ctx; SHA2_CTX sha256_ctx;