Skip to content

Commit

Permalink
refactor: Do not ignore errors in canonical hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
lubux committed Nov 22, 2023
1 parent 708c2ad commit fb84e16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions openpgp/canonical_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ func writeCanonical(cw io.Writer, buf []byte, s *int) (int, error) {
if c == '\r' {
*s = 1
} else if c == '\n' {
cw.Write(buf[start:i])
cw.Write(newline)
if _, err := cw.Write(buf[start:i]); err != nil {
return 0, err
}
if _, err := cw.Write(newline); err != nil {
return 0, err
}
start = i + 1
}
case 1:
*s = 0
}
}

cw.Write(buf[start:])
if _, err := cw.Write(buf[start:]); err != nil {
return 0, err
}
return len(buf), nil
}

Expand Down
12 changes: 9 additions & 3 deletions openpgp/v2/canonical_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,22 @@ func writeCanonical(cw io.Writer, buf []byte, s *int) (int, error) {
if c == '\r' {
*s = 1
} else if c == '\n' {
cw.Write(buf[start:i])
cw.Write(newline)
if _, err := cw.Write(buf[start:i]); err != nil {
return 0, err
}
if _, err := cw.Write(newline); err != nil {
return 0, err
}
start = i + 1
}
case 1:
*s = 0
}
}

cw.Write(buf[start:])
if _, err := cw.Write(buf[start:]); err != nil {
return 0, err
}
return len(buf), nil
}

Expand Down

0 comments on commit fb84e16

Please sign in to comment.