forked from quic-go/quic-go
remove the error return value from wire.Header.GetLength
Using an invalid packet number length would error on Header.Write(), so it's not necessary to check this on GetLength().
This commit is contained in:
@@ -86,21 +86,18 @@ func (h *Header) writeShortHeader(b *bytes.Buffer, v protocol.VersionNumber) err
|
||||
}
|
||||
|
||||
// GetLength determines the length of the Header.
|
||||
func (h *Header) GetLength(v protocol.VersionNumber) (protocol.ByteCount, error) {
|
||||
func (h *Header) GetLength(v protocol.VersionNumber) protocol.ByteCount {
|
||||
if h.IsLongHeader {
|
||||
length := 1 /* type byte */ + 4 /* version */ + 1 /* conn id len byte */ + protocol.ByteCount(h.DestConnectionID.Len()+h.SrcConnectionID.Len()) + protocol.ByteCount(h.PacketNumberLen) + utils.VarIntLen(uint64(h.PayloadLen))
|
||||
if h.Type == protocol.PacketTypeInitial {
|
||||
length += utils.VarIntLen(uint64(len(h.Token))) + protocol.ByteCount(len(h.Token))
|
||||
}
|
||||
return length, nil
|
||||
return length
|
||||
}
|
||||
|
||||
length := protocol.ByteCount(1 /* type byte */ + h.DestConnectionID.Len())
|
||||
if h.PacketNumberLen != protocol.PacketNumberLen1 && h.PacketNumberLen != protocol.PacketNumberLen2 && h.PacketNumberLen != protocol.PacketNumberLen4 {
|
||||
return 0, fmt.Errorf("invalid packet number length: %d", h.PacketNumberLen)
|
||||
}
|
||||
length += protocol.ByteCount(h.PacketNumberLen)
|
||||
return length, nil
|
||||
return length
|
||||
}
|
||||
|
||||
// Log logs the Header
|
||||
|
||||
@@ -317,13 +317,6 @@ var _ = Describe("Header", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(buf.Len()).To(Equal(5))
|
||||
})
|
||||
|
||||
It("errors when given an invalid packet number length", func() {
|
||||
h := &Header{PacketNumberLen: 5}
|
||||
_, err := h.GetLength(versionIETFHeader)
|
||||
Expect(err).To(MatchError("invalid packet number length: 5"))
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Context("Logging", func() {
|
||||
|
||||
Reference in New Issue
Block a user