add a function to determine the length of a short header

This commit is contained in:
Marten Seemann
2022-08-30 18:58:37 +03:00
parent d72aa25fb8
commit 4bf50901e8
3 changed files with 10 additions and 2 deletions

View File

@@ -50,6 +50,10 @@ func ParseShortHeader(data []byte, connIDLen int) (length int, _ protocol.Packet
return 1 + connIDLen + int(pnLen), pn, pnLen, kp, err
}
func ShortHeaderLen(dest protocol.ConnectionID, pnLen protocol.PacketNumberLen) protocol.ByteCount {
return 1 + protocol.ByteCount(dest.Len()) + protocol.ByteCount(pnLen)
}
func LogShortHeader(logger utils.Logger, dest protocol.ConnectionID, pn protocol.PacketNumber, pnLen protocol.PacketNumberLen, kp protocol.KeyPhaseBit) {
logger.Debugf("\tShort Header{DestConnectionID: %s, PacketNumber: %d, PacketNumberLen: %d, KeyPhase: %s}", dest, pn, pnLen, kp)
}

View File

@@ -70,6 +70,11 @@ var _ = Describe("Short Header", func() {
})
})
It("determines the length", func() {
Expect(ShortHeaderLen(protocol.ParseConnectionID([]byte{1, 2, 3, 4}), protocol.PacketNumberLen3)).To(BeEquivalentTo(8))
Expect(ShortHeaderLen(protocol.ParseConnectionID([]byte{}), protocol.PacketNumberLen1)).To(BeEquivalentTo(2))
})
Context("logging", func() {
var (
buf *bytes.Buffer