count diversification nonce in public header length

fixes #161
This commit is contained in:
Lucas Clemente
2016-06-02 12:40:14 +02:00
parent 252e884076
commit 1896003f42
2 changed files with 11 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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() {