diff options
| author | Patrick Steinhardt <ps@pks.im> | 2025-01-31 13:55:28 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-01-31 10:06:10 -0800 |
| commit | 52eef501e17078b369da571d7e6b72c7494bb779 (patch) | |
| tree | 706be7e5e77e83bb4265e7619adc0f9346719339 /hash.h | |
| parent | 0cbcba54550b1ea108e977c24b835e07b96b1c0e (diff) | |
| download | git-52eef501e17078b369da571d7e6b72c7494bb779.tar.xz | |
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hash.h')
| -rw-r--r-- | hash.h | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -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); |
