diff options
Diffstat (limited to 'hash.h')
| -rw-r--r-- | hash.h | 43 |
1 files changed, 32 insertions, 11 deletions
@@ -234,19 +234,20 @@ enum get_oid_result { #endif /* A suitably aligned type for stack allocations of hash contexts. */ -union git_hash_ctx { - git_SHA_CTX sha1; - git_SHA_CTX_unsafe sha1_unsafe; - - git_SHA256_CTX sha256; +struct git_hash_ctx { + const struct git_hash_algo *algop; + union { + git_SHA_CTX sha1; + git_SHA_CTX_unsafe sha1_unsafe; + git_SHA256_CTX sha256; + } state; }; -typedef union git_hash_ctx git_hash_ctx; -typedef void (*git_hash_init_fn)(git_hash_ctx *ctx); -typedef void (*git_hash_clone_fn)(git_hash_ctx *dst, const git_hash_ctx *src); -typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len); -typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx); -typedef void (*git_hash_final_oid_fn)(struct object_id *oid, git_hash_ctx *ctx); +typedef void (*git_hash_init_fn)(struct git_hash_ctx *ctx); +typedef void (*git_hash_clone_fn)(struct git_hash_ctx *dst, const struct git_hash_ctx *src); +typedef void (*git_hash_update_fn)(struct git_hash_ctx *ctx, const void *in, size_t len); +typedef void (*git_hash_final_fn)(unsigned char *hash, struct git_hash_ctx *ctx); +typedef void (*git_hash_final_oid_fn)(struct object_id *oid, struct git_hash_ctx *ctx); struct git_hash_algo { /* @@ -296,6 +297,26 @@ struct git_hash_algo { }; extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS]; +static inline void git_hash_clone(struct git_hash_ctx *dst, const struct git_hash_ctx *src) +{ + src->algop->clone_fn(dst, src); +} + +static inline void git_hash_update(struct git_hash_ctx *ctx, const void *in, size_t len) +{ + ctx->algop->update_fn(ctx, in, len); +} + +static inline void git_hash_final(unsigned char *hash, struct git_hash_ctx *ctx) +{ + ctx->algop->final_fn(hash, ctx); +} + +static inline void git_hash_final_oid(struct object_id *oid, struct git_hash_ctx *ctx) +{ + ctx->algop->final_oid_fn(oid, ctx); +} + /* * Return a GIT_HASH_* constant based on the name. Returns GIT_HASH_UNKNOWN if * the name doesn't match a known algorithm. |
