Skip to content

Commit 32daa6b

Browse files
ttaylorrgitster
authored andcommitted
t/helper/test-sha1: prepare for an unsafe mode
With the new "unsafe" SHA-1 build knob, it would be convenient to have a test-tool that can exercise Git's unsafe SHA-1 wrappers for testing, similar to 't/helper/test-tool sha1'. Prepare for such a helper by altering the implementation of that test-tool (in cmd_hash_impl(), which is generic and parameterized over different hash functions) to conditionally run the unsafe variants of the chosen hash function. The following commit will add a new test-tool which makes use of this new parameter. Signed-off-by: Taylor Blau <[email protected]> base-commit: d8c1fc7 Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4083a6f commit 32daa6b

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

t/helper/test-hash.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "test-tool.h"
22
#include "hex.h"
33

4-
int cmd_hash_impl(int ac, const char **av, int algo)
4+
int cmd_hash_impl(int ac, const char **av, int algo, int unsafe)
55
{
66
git_hash_ctx ctx;
77
unsigned char hash[GIT_MAX_HEXSZ];
@@ -27,7 +27,10 @@ int cmd_hash_impl(int ac, const char **av, int algo)
2727
die("OOPS");
2828
}
2929

30-
algop->init_fn(&ctx);
30+
if (unsafe)
31+
algop->unsafe_init_fn(&ctx);
32+
else
33+
algop->init_fn(&ctx);
3134

3235
while (1) {
3336
ssize_t sz, this_sz;
@@ -46,9 +49,15 @@ int cmd_hash_impl(int ac, const char **av, int algo)
4649
}
4750
if (this_sz == 0)
4851
break;
49-
algop->update_fn(&ctx, buffer, this_sz);
52+
if (unsafe)
53+
algop->unsafe_update_fn(&ctx, buffer, this_sz);
54+
else
55+
algop->update_fn(&ctx, buffer, this_sz);
5056
}
51-
algop->final_fn(hash, &ctx);
57+
if (unsafe)
58+
algop->unsafe_final_fn(hash, &ctx);
59+
else
60+
algop->final_fn(hash, &ctx);
5261

5362
if (binary)
5463
fwrite(hash, 1, algop->rawsz, stdout);

t/helper/test-sha1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int cmd__sha1(int ac, const char **av)
55
{
6-
return cmd_hash_impl(ac, av, GIT_HASH_SHA1);
6+
return cmd_hash_impl(ac, av, GIT_HASH_SHA1, 0);
77
}
88

99
int cmd__sha1_is_sha1dc(int argc UNUSED, const char **argv UNUSED)

t/helper/test-sha256.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
int cmd__sha256(int ac, const char **av)
55
{
6-
return cmd_hash_impl(ac, av, GIT_HASH_SHA256);
6+
return cmd_hash_impl(ac, av, GIT_HASH_SHA256, 0);
77
}

t/helper/test-tool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ int cmd__windows_named_pipe(int argc, const char **argv);
8181
#endif
8282
int cmd__write_cache(int argc, const char **argv);
8383

84-
int cmd_hash_impl(int ac, const char **av, int algo);
84+
int cmd_hash_impl(int ac, const char **av, int algo, int unsafe);
8585

8686
#endif

0 commit comments

Comments
 (0)