diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-22 14:18:48 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-27 20:15:09 -0500 |
commit | 0e53e55d7b400e303caf271469f584a7cf92036b (patch) | |
tree | cca08b6c2aacc6b4c6ef06d1303a582c955368b6 /src | |
parent | a9fc14b0f515ec8d27ac7c854c2884b27ebd079e (diff) | |
download | libgit2-0e53e55d7b400e303caf271469f584a7cf92036b.tar.gz |
hash: introduce git_hash_fmt
A simple hash-to-hexadigit formatter.
Diffstat (limited to 'src')
-rw-r--r-- | src/hash.c | 16 | ||||
-rw-r--r-- | src/hash.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/hash.c b/src/hash.c index 92e7ff219..98ceb05d2 100644 --- a/src/hash.c +++ b/src/hash.c @@ -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; +} diff --git a/src/hash.h b/src/hash.h index 2b2eaf6d6..507c1cb25 100644 --- a/src/hash.h +++ b/src/hash.h @@ -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 |