mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
parent
c063fb1dd3
commit
3ba8ec73d8
3 changed files with 29 additions and 7 deletions
|
@ -31,11 +31,16 @@ func (u *packetUnpacker) Unpack(publicHeaderBinary []byte, hdr *publicHeader, r
|
|||
}
|
||||
r = bytes.NewReader(plaintext)
|
||||
|
||||
privateFlag, err := r.ReadByte()
|
||||
if err != nil {
|
||||
return nil, qerr.MissingPayload
|
||||
// read private flag byte, for QUIC Version < 34
|
||||
var entropyBit bool
|
||||
if u.version < protocol.Version34 {
|
||||
var privateFlag uint8
|
||||
privateFlag, err = r.ReadByte()
|
||||
if err != nil {
|
||||
return nil, qerr.MissingPayload
|
||||
}
|
||||
entropyBit = privateFlag&0x01 > 0
|
||||
}
|
||||
entropyBit := privateFlag&0x01 > 0
|
||||
|
||||
if r.Len() == 0 {
|
||||
return nil, qerr.MissingPayload
|
||||
|
|
|
@ -35,22 +35,38 @@ var _ = Describe("Packet unpacker", func() {
|
|||
})
|
||||
|
||||
setReader := func(data []byte) {
|
||||
r = bytes.NewReader(aead.Seal(0, hdrBin, append([]byte{0x01}, data...)))
|
||||
if unpacker.version < protocol.Version34 { // add private flag
|
||||
data = append([]byte{0x01}, data...)
|
||||
}
|
||||
r = bytes.NewReader(aead.Seal(0, hdrBin, data))
|
||||
}
|
||||
|
||||
It("returns an error for empty packets that don't have a private flag", func() {
|
||||
It("returns an error for empty packets that don't have a private flag, for QUIC Version < 34", func() {
|
||||
// don't use setReader here, since it adds a private flag
|
||||
unpacker.version = protocol.Version33
|
||||
r = bytes.NewReader(aead.Seal(0, hdrBin, []byte{}))
|
||||
_, err := unpacker.Unpack(hdrBin, hdr, r)
|
||||
Expect(err).To(MatchError(qerr.MissingPayload))
|
||||
})
|
||||
|
||||
It("returns an error for empty packets that have a private flag", func() {
|
||||
It("returns an error for empty packets that have a private flag, for QUIC Version < 34", func() {
|
||||
unpacker.version = protocol.Version33
|
||||
setReader(nil)
|
||||
_, err := unpacker.Unpack(hdrBin, hdr, r)
|
||||
Expect(err).To(MatchError(qerr.MissingPayload))
|
||||
})
|
||||
|
||||
It("does not read read a private flag for QUIC Version >= 34", func() {
|
||||
unpacker.version = protocol.Version34
|
||||
f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"}
|
||||
err := f.Write(buf, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
setReader(buf.Bytes())
|
||||
packet, err := unpacker.Unpack(hdrBin, hdr, r)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(packet.frames).To(Equal([]frames.Frame{f}))
|
||||
})
|
||||
|
||||
It("unpacks stream frames", func() {
|
||||
f := &frames.StreamFrame{
|
||||
StreamID: 1,
|
||||
|
|
|
@ -15,6 +15,7 @@ const (
|
|||
Version31
|
||||
Version32
|
||||
Version33
|
||||
Version34
|
||||
)
|
||||
|
||||
// SupportedVersions lists the versions that the server supports
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue