commit 8d288f1d0517356ff749a30b5fd734b5d5d3f1ac from: Omar Polo via: Thomas Adam date: Fri Jul 12 06:00:18 2024 UTC add got_hash_digest{,_string}_length() These will be very much useful in the near future. commit - 72e411a0ac43390974f08a783aa0332ee9970a00 commit + 8d288f1d0517356ff749a30b5fd734b5d5d3f1ac 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;