mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
move packet number decoding to the unpacker
This commit is contained in:
parent
c06a0ca037
commit
a8e5309cd1
4 changed files with 43 additions and 25 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
"github.com/lucas-clemente/quic-go/internal/qerr"
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
"github.com/lucas-clemente/quic-go/internal/wire"
|
||||
)
|
||||
|
||||
|
@ -22,7 +23,10 @@ type quicAEAD interface {
|
|||
|
||||
// The packetUnpacker unpacks QUIC packets.
|
||||
type packetUnpacker struct {
|
||||
aead quicAEAD
|
||||
aead quicAEAD
|
||||
|
||||
largestRcvdPacketNumber protocol.PacketNumber
|
||||
|
||||
version protocol.VersionNumber
|
||||
}
|
||||
|
||||
|
@ -36,6 +40,12 @@ func newPacketUnpacker(aead quicAEAD, version protocol.VersionNumber) unpacker {
|
|||
}
|
||||
|
||||
func (u *packetUnpacker) Unpack(headerBinary []byte, hdr *wire.ExtendedHeader, data []byte) (*unpackedPacket, error) {
|
||||
hdr.PacketNumber = protocol.DecodePacketNumber(
|
||||
hdr.PacketNumberLen,
|
||||
u.largestRcvdPacketNumber,
|
||||
hdr.PacketNumber,
|
||||
)
|
||||
|
||||
buf := *getPacketBuffer()
|
||||
buf = buf[:0]
|
||||
defer putPacketBuffer(&buf)
|
||||
|
@ -61,6 +71,9 @@ func (u *packetUnpacker) Unpack(headerBinary []byte, hdr *wire.ExtendedHeader, d
|
|||
return nil, qerr.Error(qerr.DecryptionFailure, err.Error())
|
||||
}
|
||||
|
||||
// Only do this after decrypting, so we are sure the packet is not attacker-controlled
|
||||
u.largestRcvdPacketNumber = utils.MaxPacketNumber(u.largestRcvdPacketNumber, hdr.PacketNumber)
|
||||
|
||||
fs, err := u.parseFrames(decrypted)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue