Commit 0e53e55d by Edward Thomson

hash: introduce git_hash_fmt

A simple hash-to-hexadigit formatter.
parent a9fc14b0
......@@ -124,3 +124,19 @@ done:
return error;
}
int git_hash_fmt(char *out, unsigned char *hash, size_t hash_len)
{
static char hex[] = "0123456789abcdef";
char *str = out;
size_t i;
for (i = 0; i < hash_len; i++) {
*str++ = hex[hash[i] >> 4];
*str++ = hex[hash[i] & 0x0f];
}
*str++ = '\0';
return 0;
}
......@@ -41,4 +41,6 @@ int git_hash_final(unsigned char *out, git_hash_ctx *c);
int git_hash_buf(unsigned char *out, const void *data, size_t len, git_hash_algorithm_t algorithm);
int git_hash_vec(unsigned char *out, git_str_vec *vec, size_t n, git_hash_algorithm_t algorithm);
int git_hash_fmt(char *out, unsigned char *hash, size_t hash_len);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment