mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +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)
|
r = bytes.NewReader(plaintext)
|
||||||
|
|
||||||
privateFlag, err := r.ReadByte()
|
// read private flag byte, for QUIC Version < 34
|
||||||
if err != nil {
|
var entropyBit bool
|
||||||
return nil, qerr.MissingPayload
|
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 {
|
if r.Len() == 0 {
|
||||||
return nil, qerr.MissingPayload
|
return nil, qerr.MissingPayload
|
||||||
|
|
|
@ -35,22 +35,38 @@ var _ = Describe("Packet unpacker", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
setReader := func(data []byte) {
|
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
|
// don't use setReader here, since it adds a private flag
|
||||||
|
unpacker.version = protocol.Version33
|
||||||
r = bytes.NewReader(aead.Seal(0, hdrBin, []byte{}))
|
r = bytes.NewReader(aead.Seal(0, hdrBin, []byte{}))
|
||||||
_, err := unpacker.Unpack(hdrBin, hdr, r)
|
_, err := unpacker.Unpack(hdrBin, hdr, r)
|
||||||
Expect(err).To(MatchError(qerr.MissingPayload))
|
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)
|
setReader(nil)
|
||||||
_, err := unpacker.Unpack(hdrBin, hdr, r)
|
_, err := unpacker.Unpack(hdrBin, hdr, r)
|
||||||
Expect(err).To(MatchError(qerr.MissingPayload))
|
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() {
|
It("unpacks stream frames", func() {
|
||||||
f := &frames.StreamFrame{
|
f := &frames.StreamFrame{
|
||||||
StreamID: 1,
|
StreamID: 1,
|
||||||
|
|
|
@ -15,6 +15,7 @@ const (
|
||||||
Version31
|
Version31
|
||||||
Version32
|
Version32
|
||||||
Version33
|
Version33
|
||||||
|
Version34
|
||||||
)
|
)
|
||||||
|
|
||||||
// SupportedVersions lists the versions that the server supports
|
// SupportedVersions lists the versions that the server supports
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue