csum-file.c: use unsafe_hash_algo()

Instead of calling the unsafe_ hash function variants directly, make use of the shared 'algop' pointer by initializing it to: f->algop = unsafe_hash_algo(the_hash_algo); , thus making all calls use the unsafe variants directly. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jan 23, 2025 at 12:34 UTC f0c266af4ea7e4d9b84955f8fed8ee8cb009cbd8
1 file changed +11 -11
csum-file.c
+11 -11
@@ -50,7 +50,7 @@ void hashflush(struct hashfile *f)
50
51 if (offset) {
52 if (!f->skip_hash)
53 - f->algop->unsafe_update_fn(&f->ctx, f->buffer, offset);
53 + f->algop->update_fn(&f->ctx, f->buffer, offset);
54 flush(f, f->buffer, offset);
55 f->offset = 0;
56 }
@@ -73,7 +73,7 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result,
73 if (f->skip_hash)
74 hashclr(f->buffer, f->algop);
75 else
76 - f->algop->unsafe_final_fn(f->buffer, &f->ctx);
76 + f->algop->final_fn(f->buffer, &f->ctx);
77
78 if (result)
79 hashcpy(result, f->buffer, f->algop);
@@ -128,7 +128,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count)
128 * f->offset is necessarily zero.
129 */
130 if (!f->skip_hash)
131 - f->algop->unsafe_update_fn(&f->ctx, buf, nr);
131 + f->algop->update_fn(&f->ctx, buf, nr);
132 flush(f, buf, nr);
133 } else {
134 /*
@@ -175,8 +175,8 @@ static struct hashfile *hashfd_internal(int fd, const char *name,
175 f->do_crc = 0;
176 f->skip_hash = 0;
177
178 - f->algop = the_hash_algo;
179 - f->algop->unsafe_init_fn(&f->ctx);
178 + f->algop = unsafe_hash_algo(the_hash_algo);
179 + f->algop->init_fn(&f->ctx);
180
181 f->buffer_len = buffer_len;
182 f->buffer = xmalloc(buffer_len);
@@ -210,7 +210,7 @@ void hashfile_checkpoint(struct hashfile *f, struct hashfile_checkpoint *checkpo
210 {
211 hashflush(f);
212 checkpoint->offset = f->total;
213 - f->algop->unsafe_clone_fn(&checkpoint->ctx, &f->ctx);
213 + f->algop->clone_fn(&checkpoint->ctx, &f->ctx);
214 }
215
216 int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint)
@@ -221,7 +221,7 @@ int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint
221 lseek(f->fd, offset, SEEK_SET) != offset)
222 return -1;
223 f->total = offset;
224 - f->algop->unsafe_clone_fn(&f->ctx, &checkpoint->ctx);
224 + f->algop->clone_fn(&f->ctx, &checkpoint->ctx);
225 f->offset = 0; /* hashflush() was called in checkpoint */
226 return 0;
227 }
@@ -242,15 +242,15 @@ int hashfile_checksum_valid(const unsigned char *data, size_t total_len)
242 {
243 unsigned char got[GIT_MAX_RAWSZ];
244 git_hash_ctx ctx;
245 - const struct git_hash_algo *algop = the_hash_algo;
245 + const struct git_hash_algo *algop = unsafe_hash_algo(the_hash_algo);
246 size_t data_len = total_len - algop->rawsz;
247
248 if (total_len < algop->rawsz)
249 return 0; /* say "too short"? */
250
251 - algop->unsafe_init_fn(&ctx);
252 - algop->unsafe_update_fn(&ctx, data, data_len);
253 - algop->unsafe_final_fn(got, &ctx);
251 + algop->init_fn(&ctx);
252 + algop->update_fn(&ctx, data, data_len);
253 + algop->final_fn(got, &ctx);
254
255 return hasheq(got, data + data_len, algop);
256 }