From 52eef501e17078b369da571d7e6b72c7494bb779 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 31 Jan 2025 13:55:28 +0100 Subject: hash: convert hashing context to a structure The `git_hash_context` is a union containing the different hash-specific states for SHA1, its unsafe variant as well as SHA256. We know that only one of these states will ever be in use at the same time because hash contexts cannot be used for multiple different hashes at the same point in time. We're about to extend the structure though to keep track of the hash algorithm used to initialize the context, which is impossible to do while the context is a union. Refactor it to instead be a structure that contains the union of context states. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- hash.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'hash.h') diff --git a/hash.h b/hash.h index ad2c919991..5b88d9b714 100644 --- a/hash.h +++ b/hash.h @@ -234,13 +234,14 @@ 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 { + 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 struct 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); -- cgit v1.3-6-g1900