aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/hash.c b/hash.c
index 4a04ecb50e..4977e13de6 100644
--- a/hash.c
+++ b/hash.c
@@ -241,7 +241,47 @@ const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
return oid_to_hex_r(buf, algop->empty_tree);
}
-int hash_algo_by_name(const char *name)
+const struct git_hash_algo *hash_algo_ptr_by_offset(uint32_t algo)
+{
+ return &hash_algos[algo];
+}
+
+struct git_hash_ctx *git_hash_alloc(void)
+{
+ return malloc(sizeof(struct git_hash_ctx));
+}
+
+void git_hash_free(struct git_hash_ctx *ctx)
+{
+ free(ctx);
+}
+
+void git_hash_init(struct git_hash_ctx *ctx, const struct git_hash_algo *algop)
+{
+ algop->init_fn(ctx);
+}
+
+void git_hash_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src)
+{
+ src->algop->clone_fn(dst, src);
+}
+
+void git_hash_update(struct git_hash_ctx *ctx, const void *in, size_t len)
+{
+ ctx->algop->update_fn(ctx, in, len);
+}
+
+void git_hash_final(unsigned char *hash, struct git_hash_ctx *ctx)
+{
+ ctx->algop->final_fn(hash, ctx);
+}
+
+void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx *ctx)
+{
+ ctx->algop->final_oid_fn(oid, ctx);
+}
+
+uint32_t hash_algo_by_name(const char *name)
{
if (!name)
return GIT_HASH_UNKNOWN;
@@ -251,7 +291,7 @@ int hash_algo_by_name(const char *name)
return GIT_HASH_UNKNOWN;
}
-int hash_algo_by_id(uint32_t format_id)
+uint32_t hash_algo_by_id(uint32_t format_id)
{
for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
if (format_id == hash_algos[i].format_id)
@@ -259,7 +299,7 @@ int hash_algo_by_id(uint32_t format_id)
return GIT_HASH_UNKNOWN;
}
-int hash_algo_by_length(size_t len)
+uint32_t hash_algo_by_length(size_t len)
{
for (size_t i = 1; i < GIT_HASH_NALGOS; i++)
if (len == hash_algos[i].rawsz)