Skip to content

Commit

Permalink
Replace AddFromBundle bufio Scanner with Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored and csweichel committed Jul 8, 2024
1 parent aa1745e commit 9e23bed
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions pkg/leeway/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,18 @@ func (a *AttestationBundle) Add(env *provenance.Envelope) error {
// This function ensures entries are unique.
// This function is not synchronised.
func (a *AttestationBundle) AddFromBundle(other io.Reader) error {
// TOOD(cw): use something other than a scanner. We've seen "Token Too Long" in first trials already.
scan := bufio.NewScanner(other)
scan.Buffer(make([]byte, maxBundleEntrySize), maxBundleEntrySize)
for scan.Scan() {
reader := bufio.NewReader(other)
for {
line, err := reader.ReadBytes('\n')
if err != nil {
if err == io.EOF {
break
}
return err
}

hash := sha256.New()
_, err := hash.Write(scan.Bytes())
_, err = hash.Write(line)
if err != nil {
return err
}
Expand All @@ -471,20 +477,12 @@ func (a *AttestationBundle) AddFromBundle(other io.Reader) error {
continue
}

_, err = a.out.Write(scan.Bytes())
if err != nil {
return err
}
_, err = a.out.Write([]byte{'\n'})
_, err = a.out.Write(line)
if err != nil {
return err
}
a.keys[key] = struct{}{}
}

if scan.Err() != nil {
return scan.Err()
}
return nil
}

Expand Down

0 comments on commit 9e23bed

Please sign in to comment.