diff options
| author | 2026-03-28 04:19:44 +0000 | |
|---|---|---|
| committer | 2026-03-28 04:20:29 +0000 | |
| commit | 402ef2733813d128631ca4aea18c2908c74340d5 (patch) | |
| tree | e03a90b6f41411bd62e7339390802c5c50082850 /object/store/packed/pack_idx_checksum.go | |
| parent | object/store: Rename from object/storer (diff) | |
| signature | No signature | |
object/store: Rename back from storer; rename Store to ReadingStore v0.1.118
Diffstat (limited to 'object/store/packed/pack_idx_checksum.go')
| -rw-r--r-- | object/store/packed/pack_idx_checksum.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/object/store/packed/pack_idx_checksum.go b/object/store/packed/pack_idx_checksum.go new file mode 100644 index 00000000..28d4c3db --- /dev/null +++ b/object/store/packed/pack_idx_checksum.go @@ -0,0 +1,34 @@ +package packed + +import ( + "bytes" + "fmt" + + objectid "codeberg.org/lindenii/furgit/object/id" +) + +// verifyMappedPackMatchesMappedIdx compares one mapped pack trailer hash with +// the pack hash recorded in one mapped idx trailer. +func verifyMappedPackMatchesMappedIdx(packData, idxData []byte, algo objectid.Algorithm) error { + hashSize := algo.Size() + if hashSize <= 0 { + return objectid.ErrInvalidAlgorithm + } + + if len(packData) < hashSize { + return fmt.Errorf("objectstore/packed: pack too short for trailer hash") + } + + if len(idxData) < hashSize*2 { + return fmt.Errorf("objectstore/packed: idx too short for trailer hashes") + } + + packTrailerHash := packData[len(packData)-hashSize:] + + idxPackHash := idxData[len(idxData)-hashSize*2 : len(idxData)-hashSize] + if !bytes.Equal(packTrailerHash, idxPackHash) { + return fmt.Errorf("objectstore/packed: pack hash does not match idx") + } + + return nil +} |
