forked from quic-go/quic-go
wire: use quicvarint.Parse when parsing frames (#4484)
* wire: add benchmarks for the frame parser * wire: use quicvarint.Parse when parsing frames * wire: always use io.EOF for too short frames
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"github.com/quic-go/quic-go/internal/protocol"
|
||||
@@ -13,19 +12,20 @@ import (
|
||||
var _ = Describe("PATH_RESPONSE frame", func() {
|
||||
Context("when parsing", func() {
|
||||
It("accepts sample frame", func() {
|
||||
b := bytes.NewReader([]byte{1, 2, 3, 4, 5, 6, 7, 8})
|
||||
f, err := parsePathResponseFrame(b, protocol.Version1)
|
||||
b := []byte{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
f, l, err := parsePathResponseFrame(b, protocol.Version1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(b.Len()).To(BeZero())
|
||||
Expect(f.Data).To(Equal([8]byte{1, 2, 3, 4, 5, 6, 7, 8}))
|
||||
Expect(l).To(Equal(len(b)))
|
||||
})
|
||||
|
||||
It("errors on EOFs", func() {
|
||||
data := []byte{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
_, err := parsePathResponseFrame(bytes.NewReader(data), protocol.Version1)
|
||||
_, l, err := parsePathResponseFrame(data, protocol.Version1)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(l).To(Equal(len(data)))
|
||||
for i := range data {
|
||||
_, err := parsePathResponseFrame(bytes.NewReader(data[:i]), protocol.Version1)
|
||||
_, _, err := parsePathResponseFrame(data[:i], protocol.Version1)
|
||||
Expect(err).To(MatchError(io.EOF))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user