Skip to content

Commit 800edc6

Browse files
feat: Implement an option to control hash verification (libgit2#671) (libgit2#673)
Add a binding to enable/disable hash verification using the `GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION` option. Change type: #minor (cherry picked from commit c366419) Co-authored-by: Suhaib Mujahid <[email protected]>
1 parent 7b9a768 commit 800edc6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

settings.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ func EnableCaching(enabled bool) error {
9393
}
9494
}
9595

96+
func EnableStrictHashVerification(enabled bool) error {
97+
if enabled {
98+
return setSizet(C.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1)
99+
} else {
100+
return setSizet(C.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0)
101+
}
102+
}
103+
96104
func CachedMemory() (current int, allowed int, err error) {
97105
return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY)
98106
}

settings_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ func TestEnableCaching(t *testing.T) {
5757
checkFatal(t, err)
5858
}
5959

60+
func TestEnableStrictHashVerification(t *testing.T) {
61+
err := EnableStrictHashVerification(false)
62+
checkFatal(t, err)
63+
64+
err = EnableStrictHashVerification(true)
65+
checkFatal(t, err)
66+
}
67+
6068
func TestCachedMemory(t *testing.T) {
6169
current, allowed, err := CachedMemory()
6270
checkFatal(t, err)
@@ -80,4 +88,4 @@ func TestSetCacheMaxSize(t *testing.T) {
8088
// revert to default 256MB
8189
err = SetCacheMaxSize(256 * 1024 * 1024)
8290
checkFatal(t, err)
83-
}
91+
}

0 commit comments

Comments
 (0)