feat: Implement an option to control hash verification (#671) (#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 c3664193f3)

Co-authored-by: Suhaib Mujahid <suhaibmujahid@gmail.com>
This commit is contained in:
github-actions[bot] 2020-11-02 18:44:37 -08:00 committed by GitHub
parent 7b9a768b08
commit 800edc61bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -93,6 +93,14 @@ func EnableCaching(enabled bool) error {
} }
} }
func EnableStrictHashVerification(enabled bool) error {
if enabled {
return setSizet(C.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1)
} else {
return setSizet(C.GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0)
}
}
func CachedMemory() (current int, allowed int, err error) { func CachedMemory() (current int, allowed int, err error) {
return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY) return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY)
} }

View File

@ -57,6 +57,14 @@ func TestEnableCaching(t *testing.T) {
checkFatal(t, err) checkFatal(t, err)
} }
func TestEnableStrictHashVerification(t *testing.T) {
err := EnableStrictHashVerification(false)
checkFatal(t, err)
err = EnableStrictHashVerification(true)
checkFatal(t, err)
}
func TestCachedMemory(t *testing.T) { func TestCachedMemory(t *testing.T) {
current, allowed, err := CachedMemory() current, allowed, err := CachedMemory()
checkFatal(t, err) checkFatal(t, err)
@ -80,4 +88,4 @@ func TestSetCacheMaxSize(t *testing.T) {
// revert to default 256MB // revert to default 256MB
err = SetCacheMaxSize(256 * 1024 * 1024) err = SetCacheMaxSize(256 * 1024 * 1024)
checkFatal(t, err) checkFatal(t, err)
} }