implement a function to parse the version number of a Long Header packet

This commit is contained in:
Marten Seemann
2022-08-28 13:12:16 +03:00
parent ec9c824d98
commit d7097d74f0
2 changed files with 27 additions and 0 deletions

View File

@@ -111,6 +111,24 @@ var _ = Describe("Header Parsing", func() {
Expect(Is0RTTPacket(append(zeroRTTHeader, []byte("foobar")...))).To(BeTrue())
})
})
Context("parsing the version", func() {
It("parses the version", func() {
b := []byte{0x80, 0xde, 0xad, 0xbe, 0xef}
v, err := ParseVersion(b)
Expect(err).ToNot(HaveOccurred())
Expect(v).To(Equal(protocol.VersionNumber(0xdeadbeef)))
})
It("errors with EOF", func() {
b := []byte{0x80, 0xde, 0xad, 0xbe, 0xef}
_, err := ParseVersion(b)
Expect(err).ToNot(HaveOccurred())
for i := range b {
_, err := ParseVersion(b[:i])
Expect(err).To(MatchError(io.EOF))
}
})
})
Context("Identifying Version Negotiation Packets", func() {
It("identifies version negotiation packets", func() {