diff options
| author | 2026-03-26 09:17:14 +0000 | |
|---|---|---|
| committer | 2026-03-26 09:18:30 +0000 | |
| commit | 3e884f5f3d42cbc4874a04da31dde10314b0cfad (patch) | |
| tree | f5e1e325fd1a2a0801791c054010213214475d80 /commitgraph/read/hash.go | |
| parent | network/receivepack: Rename from receivepack (diff) | |
| signature | No signature | |
format: Move commitgraph and packfile here
Diffstat (limited to 'commitgraph/read/hash.go')
| -rw-r--r-- | commitgraph/read/hash.go | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/commitgraph/read/hash.go b/commitgraph/read/hash.go deleted file mode 100644 index 3a525afe..00000000 --- a/commitgraph/read/hash.go +++ /dev/null @@ -1,79 +0,0 @@ -package read - -import ( - "bytes" - "fmt" - "io" - - objectid "codeberg.org/lindenii/furgit/object/id" -) - -// HashVersion returns the commit-graph hash version. -func (reader *Reader) HashVersion() uint8 { - return reader.hashVersion -} - -func validateChainBaseHashes(algo objectid.Algorithm, chain []string, idx int, graph *layer) error { - if idx == 0 { - if len(graph.chunkBaseGraphs) != 0 { - return &MalformedError{Path: graph.path, Reason: "unexpected BASE chunk in first graph"} - } - - return nil - } - - hashSize := algo.Size() - - expectedLen := idx * hashSize - if len(graph.chunkBaseGraphs) != expectedLen { - return &MalformedError{ - Path: graph.path, - Reason: fmt.Sprintf("BASE chunk length %d does not match expected %d", len(graph.chunkBaseGraphs), expectedLen), - } - } - - for i := range idx { - start := i * hashSize - end := start + hashSize - - baseHash, err := objectid.FromBytes(algo, graph.chunkBaseGraphs[start:end]) - if err != nil { - return err - } - - if baseHash.String() != chain[i] { - return &MalformedError{ - Path: graph.path, - Reason: fmt.Sprintf("BASE chunk mismatch at index %d", i), - } - } - } - - return nil -} - -func verifyTrailerHash(data []byte, algo objectid.Algorithm, path string) error { - hashSize := algo.Size() - if len(data) < hashSize { - return &MalformedError{Path: path, Reason: "file too short for trailer"} - } - - hashImpl, err := algo.New() - if err != nil { - return err - } - - _, err = io.Copy(hashImpl, bytes.NewReader(data[:len(data)-hashSize])) - if err != nil { - return err - } - - got := hashImpl.Sum(nil) - - want := data[len(data)-hashSize:] - if !bytes.Equal(got, want) { - return &MalformedError{Path: path, Reason: "trailer hash mismatch"} - } - - return nil -} |
