aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/hash.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2022-11-25 14:07:01 +0000
committerPaulo Gomes <pjbgf@linux.com>2022-11-25 14:07:01 +0000
commit7c37589e95f6a88e470bf91d3a0ef8536702f3f4 (patch)
treea8d7351b3d6094cea5974750a312346f1c066e0a /plumbing/hash.go
parentc798d4a42004b1c8976a6a4f42f131f16d08b6fa (diff)
downloadgo-git-7c37589e95f6a88e470bf91d3a0ef8536702f3f4.tar.gz
sha1: Add collision resistent implementation
Implement the same SHA1 collision resistent algorithm used by both the Git CLI and libgit2. Only commits with input that match the unavoidable bit conditions will be further processed, which will result in different hashes. Which is the same behaviour experienced in the Git CLI and Libgit2. Users can override the hash algorithm used with: hash.RegisterHash(crypto.SHA1, sha1.New) xref links: https://github.com/libgit2/libgit2/pull/4136/commits/2dfd1294f7a694bfa9e864a9489ae3cb318a5ed0 https://github.com/git/git/commit/28dc98e343ca4eb370a29ceec4c19beac9b5c01e Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Diffstat (limited to 'plumbing/hash.go')
-rw-r--r--plumbing/hash.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/plumbing/hash.go b/plumbing/hash.go
index afc602a..2fab759 100644
--- a/plumbing/hash.go
+++ b/plumbing/hash.go
@@ -2,11 +2,12 @@ package plumbing
import (
"bytes"
- "crypto/sha1"
+ "crypto"
"encoding/hex"
- "hash"
"sort"
"strconv"
+
+ "github.com/go-git/go-git/v5/plumbing/hash"
)
// Hash SHA1 hashed content
@@ -46,7 +47,7 @@ type Hasher struct {
}
func NewHasher(t ObjectType, size int64) Hasher {
- h := Hasher{sha1.New()}
+ h := Hasher{hash.New(crypto.SHA1)}
h.Write(t.Bytes())
h.Write([]byte(" "))
h.Write([]byte(strconv.FormatInt(size, 10)))