aboutsummaryrefslogtreecommitdiff
path: root/format/pack/ingest/trailer.go
diff options
context:
space:
mode:
Diffstat (limited to 'format/pack/ingest/trailer.go')
-rw-r--r--format/pack/ingest/trailer.go58
1 files changed, 0 insertions, 58 deletions
diff --git a/format/pack/ingest/trailer.go b/format/pack/ingest/trailer.go
deleted file mode 100644
index 30ba3bb8..00000000
--- a/format/pack/ingest/trailer.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package ingest
-
-import (
- "bytes"
- "errors"
- "fmt"
- "io"
-)
-
-// finishAndFlushTrailer reads trailer hash bytes, verifies trailer checksum,
-// and optionally requires the source stream to hit EOF afterward.
-func (scanner *streamScanner) finishAndFlushTrailer(requireTrailingEOF bool) error {
- if scanner.hashSize <= 0 {
- return fmt.Errorf("format/pack/ingest: invalid hash size")
- }
-
- trailer := make([]byte, scanner.hashSize)
-
- scanner.hashEnabled = false
-
- err := scanner.readFull(trailer)
- if err != nil {
- return &PackTrailerMismatchError{}
- }
-
- scanner.packTrailer = append(scanner.packTrailer[:0], trailer...)
-
- if scanner.n-scanner.off > 0 {
- return fmt.Errorf("format/pack/ingest: pack has trailing garbage")
- }
-
- if !requireTrailingEOF {
- computed := scanner.hash.Sum(nil)
- if !bytes.Equal(computed, trailer) {
- return &PackTrailerMismatchError{}
- }
-
- return nil
- }
-
- var probe [1]byte
-
- n, err := scanner.Read(probe[:])
- if n > 0 || err == nil {
- return fmt.Errorf("format/pack/ingest: pack has trailing garbage")
- }
-
- if !errors.Is(err, io.EOF) {
- return err
- }
-
- computed := scanner.hash.Sum(nil)
- if !bytes.Equal(computed, trailer) {
- return &PackTrailerMismatchError{}
- }
-
- return nil
-}