Skip to content

Commit 6a02b45

Browse files
committed
futils: use SHA256 for checksums always
Use SHA256 for file checksums. SHA1 makes no sense as a default in 2023. Given that we're just looking at a file checksum to see if it's changed, this does not need to take repository's OID type into account or otherwise be configurable.
1 parent 8f7fc2e commit 6a02b45

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/libgit2/grafts.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct git_grafts {
1818

1919
/* File backing the graft. NULL if it's an in-memory graft */
2020
char *path;
21-
git_oid path_checksum;
21+
unsigned char path_checksum[GIT_HASH_SHA256_SIZE];
2222
};
2323

2424
int git_grafts_new(git_grafts **out)
@@ -97,7 +97,8 @@ int git_grafts_refresh(git_grafts *grafts)
9797
return 0;
9898

9999
if ((error = git_futils_readbuffer_updated(&contents, grafts->path,
100-
(grafts->path_checksum).id, &updated)) < 0) {
100+
grafts->path_checksum, &updated)) < 0) {
101+
101102
if (error == GIT_ENOTFOUND) {
102103
git_grafts_clear(grafts);
103104
error = 0;

src/util/futils.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ int git_futils_readbuffer_fd_full(git_str *buf, git_file fd)
221221
int git_futils_readbuffer_updated(
222222
git_str *out,
223223
const char *path,
224-
unsigned char checksum[GIT_HASH_SHA1_SIZE],
224+
unsigned char checksum[GIT_HASH_SHA256_SIZE],
225225
int *updated)
226226
{
227227
int error;
228228
git_file fd;
229229
struct stat st;
230230
git_str buf = GIT_STR_INIT;
231-
unsigned char checksum_new[GIT_HASH_SHA1_SIZE];
231+
unsigned char checksum_new[GIT_HASH_SHA256_SIZE];
232232

233233
GIT_ASSERT_ARG(out);
234234
GIT_ASSERT_ARG(path && *path);
@@ -261,23 +261,26 @@ int git_futils_readbuffer_updated(
261261
p_close(fd);
262262

263263
if (checksum) {
264-
if ((error = git_hash_buf(checksum_new, buf.ptr, buf.size, GIT_HASH_ALGORITHM_SHA1)) < 0) {
264+
error = git_hash_buf(checksum_new, buf.ptr,
265+
buf.size, GIT_HASH_ALGORITHM_SHA256);
266+
267+
if (error < 0) {
265268
git_str_dispose(&buf);
266269
return error;
267270
}
268271

269272
/*
270273
* If we were given a checksum, we only want to use it if it's different
271274
*/
272-
if (!memcmp(checksum, checksum_new, GIT_HASH_SHA1_SIZE)) {
275+
if (!memcmp(checksum, checksum_new, GIT_HASH_SHA256_SIZE)) {
273276
git_str_dispose(&buf);
274277
if (updated)
275278
*updated = 0;
276279

277280
return 0;
278281
}
279282

280-
memcpy(checksum, checksum_new, GIT_HASH_SHA1_SIZE);
283+
memcpy(checksum, checksum_new, GIT_HASH_SHA256_SIZE);
281284
}
282285

283286
/*

0 commit comments

Comments
 (0)