Skip to content

Commit

Permalink
Bugfix: AEAD stream reader failed to handle leftover bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
riobard committed Apr 25, 2017
1 parent 530fe56 commit de996c8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions shadowaead/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ func (r *reader) Read(b []byte) (int, error) {
// there's no more data to write or when an error occurs. Return number of
// bytes written to w and any error encountered.
func (r *reader) WriteTo(w io.Writer) (n int64, err error) {
// write decrypted bytes left over from previous record
for len(r.leftover) > 0 {
nw, ew := w.Write(r.leftover)
r.leftover = r.leftover[nw:]
n += int64(nw)
if ew != nil {
return n, ew
}
}

for {
nr, er := r.read()
if nr > 0 {
Expand Down

0 comments on commit de996c8

Please sign in to comment.