shithub: furgit

Download patch

ref: 32f48e18896061529f038eaf527f2eec0490f5df
parent: 23dc5b7fcd456485d320a0c1bd056369572accaf
author: Runxi Yu <runxiyu@umich.edu>
date: Sun Jan 18 20:03:23 EST 2026

hash: Document maxHashSize properly

--- a/hash.go
+++ b/hash.go
@@ -6,11 +6,31 @@
 	"encoding/hex"
 )
 
-const maxHashSize = 32
+// maxHashSize MUST be equal to (or larger than) the size of the
+// largest hash supported in hashFuncs.
+const maxHashSize = sha256.Size
 
 // hashAlgorithm identifies the hash algorithm used for Git object IDs.
 type hashAlgorithm uint8
 
+// hashFuncs maps hash algorithm to hash function.
+var hashFuncs = map[hashAlgorithm]hashFunc{
+	hashAlgoSHA1: func(data []byte) Hash {
+		sum := sha1.Sum(data)
+		var h Hash
+		copy(h.data[:], sum[:])
+		h.algo = hashAlgoSHA1
+		return h
+	},
+	hashAlgoSHA256: func(data []byte) Hash {
+		sum := sha256.Sum256(data)
+		var h Hash
+		copy(h.data[:], sum[:])
+		h.algo = hashAlgoSHA256
+		return h
+	},
+}
+
 const (
 	hashAlgoUnknown hashAlgorithm = iota
 	hashAlgoSHA1
@@ -49,24 +69,6 @@
 
 // hashFunc is a function that computes a hash from input data.
 type hashFunc func([]byte) Hash
-
-// hashFuncs maps hash algorithm to hash function.
-var hashFuncs = map[hashAlgorithm]hashFunc{
-	hashAlgoSHA1: func(data []byte) Hash {
-		sum := sha1.Sum(data)
-		var h Hash
-		copy(h.data[:], sum[:])
-		h.algo = hashAlgoSHA1
-		return h
-	},
-	hashAlgoSHA256: func(data []byte) Hash {
-		sum := sha256.Sum256(data)
-		var h Hash
-		copy(h.data[:], sum[:])
-		h.algo = hashAlgoSHA256
-		return h
-	},
-}
 
 // String returns a hexadecimal string representation of the hash.
 func (hash Hash) String() string {
--