diff --git a/public_header.go b/public_header.go index 37e85c42..c768223c 100644 --- a/public_header.go +++ b/public_header.go @@ -175,6 +175,7 @@ func (h *publicHeader) GetLength() (protocol.ByteCount, error) { if !h.TruncateConnectionID { length += 8 // 8 bytes for the connection ID } + length += protocol.ByteCount(len(h.DiversificationNonce)) length += protocol.ByteCount(h.PacketNumberLen) return length, nil } diff --git a/public_header_test.go b/public_header_test.go index 7826acc9..afc84b9f 100644 --- a/public_header_test.go +++ b/public_header_test.go @@ -228,6 +228,16 @@ var _ = Describe("Public Header", func() { Expect(err).ToNot(HaveOccurred()) Expect(length).To(Equal(protocol.ByteCount(1 + 8 + 2))) // 1 byte public flag, 8 byte connectionID, and packet number }) + + It("works with diversification nonce", func() { + hdr := publicHeader{ + DiversificationNonce: []byte("foo"), + PacketNumberLen: protocol.PacketNumberLen1, + } + length, err := hdr.GetLength() + Expect(err).NotTo(HaveOccurred()) + Expect(length).To(Equal(protocol.ByteCount(1 + 8 + 3 + 1))) + }) }) Context("packet number length", func() {