diff options
author | Yawning Angel <yawning@schwanenlied.me> | 2014-05-26 04:43:46 +0000 |
---|---|---|
committer | Yawning Angel <yawning@schwanenlied.me> | 2014-05-26 04:43:46 +0000 |
commit | b579f6f4d4390997573af7d05bf83dc16d533479 (patch) | |
tree | 21f83a5cf8c61816c53a1266c2ca01a5f136d5ab /framing | |
parent | 49d3f6e8bbbdd72cb7445b0ff4807c43afac4ce4 (diff) |
Use io.ReadFull in places where it is appropriate.
Diffstat (limited to 'framing')
-rw-r--r-- | framing/framing.go | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/framing/framing.go b/framing/framing.go index b51a7af..66eeff5 100644 --- a/framing/framing.go +++ b/framing/framing.go @@ -240,12 +240,9 @@ func (decoder *Decoder) Decode(data []byte, frames *bytes.Buffer) (int, error) { // Remove the length field from the buffer. var obfsLen [lengthLength]byte - n, err := frames.Read(obfsLen[:]) + _, err := io.ReadFull(frames, obfsLen[:]) if err != nil { return 0, err - } else if n != lengthLength { - // Should *NEVER* happen, since at least 2 bytes exist. - panic(fmt.Sprintf("BUG: Failed to read obfuscated length: %d", n)) } // Derive the nonce the peer used. @@ -284,13 +281,9 @@ func (decoder *Decoder) Decode(data []byte, frames *bytes.Buffer) (int, error) { // Unseal the frame. var box [maxFrameLength]byte - n, err := frames.Read(box[:decoder.nextLength]) + n, err := io.ReadFull(frames, box[:decoder.nextLength]) if err != nil { return 0, err - } else if n != int(decoder.nextLength) { - // Should *NEVER* happen, since the length is checked. - panic(fmt.Sprintf("BUG: Failed to read secretbox, got %d, should have %d", - n, decoder.nextLength)) } out, ok := secretbox.Open(data[:0], box[:n], &decoder.nextNonce, &decoder.key) if !ok || decoder.nextLengthInvalid { |