Skip to content

Commit 9e23bed

Browse files
aledbfcsweichel
authored andcommitted
Replace AddFromBundle bufio Scanner with Reader
1 parent aa1745e commit 9e23bed

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

pkg/leeway/provenance.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,18 @@ func (a *AttestationBundle) Add(env *provenance.Envelope) error {
456456
// This function ensures entries are unique.
457457
// This function is not synchronised.
458458
func (a *AttestationBundle) AddFromBundle(other io.Reader) error {
459-
// TOOD(cw): use something other than a scanner. We've seen "Token Too Long" in first trials already.
460-
scan := bufio.NewScanner(other)
461-
scan.Buffer(make([]byte, maxBundleEntrySize), maxBundleEntrySize)
462-
for scan.Scan() {
459+
reader := bufio.NewReader(other)
460+
for {
461+
line, err := reader.ReadBytes('\n')
462+
if err != nil {
463+
if err == io.EOF {
464+
break
465+
}
466+
return err
467+
}
468+
463469
hash := sha256.New()
464-
_, err := hash.Write(scan.Bytes())
470+
_, err = hash.Write(line)
465471
if err != nil {
466472
return err
467473
}
@@ -471,20 +477,12 @@ func (a *AttestationBundle) AddFromBundle(other io.Reader) error {
471477
continue
472478
}
473479

474-
_, err = a.out.Write(scan.Bytes())
475-
if err != nil {
476-
return err
477-
}
478-
_, err = a.out.Write([]byte{'\n'})
480+
_, err = a.out.Write(line)
479481
if err != nil {
480482
return err
481483
}
482484
a.keys[key] = struct{}{}
483485
}
484-
485-
if scan.Err() != nil {
486-
return scan.Err()
487-
}
488486
return nil
489487
}
490488

0 commit comments

Comments
 (0)