remove unnecessary Raw byte slice from the header

This commit is contained in:
Marten Seemann 2019-01-03 10:14:08 +07:00
parent 3691a18849
commit 5a37e8983d
3 changed files with 3 additions and 7 deletions

View file

@ -15,7 +15,6 @@ type ExtendedHeader struct {
Header Header
typeByte byte typeByte byte
Raw []byte
PacketNumberLen protocol.PacketNumberLen PacketNumberLen protocol.PacketNumberLen
PacketNumber protocol.PacketNumber PacketNumber protocol.PacketNumber

View file

@ -66,18 +66,16 @@ func (u *packetUnpacker) Unpack(hdr *wire.Header, data []byte) (*unpackedPacket,
&data[0], &data[0],
data[hdrLen:hdrLen+4], data[hdrLen:hdrLen+4],
) )
// 3. parse the header (and learn the actual length of the packet number) // 3. parse the header (and learn the actual length of the packet number)
extHdr, err := hdr.ParseExtended(r, u.version) extHdr, err := hdr.ParseExtended(r, u.version)
if err != nil { if err != nil {
return nil, fmt.Errorf("error parsing extended header: %s", err) return nil, fmt.Errorf("error parsing extended header: %s", err)
} }
extHdr.Raw = data[:hdrLen+int(extHdr.PacketNumberLen)] extHdrLen := hdrLen + int(extHdr.PacketNumberLen)
// 4. if the packet number is shorter than 4 bytes, replace the remaining bytes with the copy we saved earlier // 4. if the packet number is shorter than 4 bytes, replace the remaining bytes with the copy we saved earlier
if extHdr.PacketNumberLen != protocol.PacketNumberLen4 { if extHdr.PacketNumberLen != protocol.PacketNumberLen4 {
copy(data[hdrLen+int(extHdr.PacketNumberLen):hdrLen+4], origPNBytes[int(extHdr.PacketNumberLen):]) copy(data[extHdrLen:hdrLen+4], origPNBytes[int(extHdr.PacketNumberLen):])
} }
data = data[hdrLen+int(extHdr.PacketNumberLen):]
pn := protocol.DecodePacketNumber( pn := protocol.DecodePacketNumber(
extHdr.PacketNumberLen, extHdr.PacketNumberLen,
@ -85,7 +83,7 @@ func (u *packetUnpacker) Unpack(hdr *wire.Header, data []byte) (*unpackedPacket,
extHdr.PacketNumber, extHdr.PacketNumber,
) )
decrypted, err := opener.Open(data[:0], data, pn, extHdr.Raw) decrypted, err := opener.Open(data[extHdrLen:extHdrLen], data[extHdrLen:], pn, data[:extHdrLen])
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -492,7 +492,6 @@ var _ = Describe("Session", func() {
It("informs the ReceivedPacketHandler", func() { It("informs the ReceivedPacketHandler", func() {
hdr := &wire.ExtendedHeader{ hdr := &wire.ExtendedHeader{
Raw: []byte("raw header"),
PacketNumber: 0x37, PacketNumber: 0x37,
PacketNumberLen: protocol.PacketNumberLen1, PacketNumberLen: protocol.PacketNumberLen1,
} }