github.com/daeuniverse/quic-go@v0.0.0-20240413031024-943f218e0810/internal/handshake/retry_test.go (about) 1 package handshake 2 3 import ( 4 "encoding/binary" 5 6 "github.com/daeuniverse/quic-go/internal/protocol" 7 8 . "github.com/onsi/ginkgo/v2" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Retry Integrity Check", func() { 13 It("calculates retry integrity tags", func() { 14 connID := protocol.ParseConnectionID([]byte{1, 2, 3, 4}) 15 fooTag := GetRetryIntegrityTag([]byte("foo"), connID, protocol.Version1) 16 barTag := GetRetryIntegrityTag([]byte("bar"), connID, protocol.Version1) 17 Expect(fooTag).ToNot(BeNil()) 18 Expect(barTag).ToNot(BeNil()) 19 Expect(*fooTag).ToNot(Equal(*barTag)) 20 }) 21 22 It("includes the original connection ID in the tag calculation", func() { 23 connID1 := protocol.ParseConnectionID([]byte{1, 2, 3, 4}) 24 connID2 := protocol.ParseConnectionID([]byte{4, 3, 2, 1}) 25 t1 := GetRetryIntegrityTag([]byte("foobar"), connID1, protocol.Version1) 26 t2 := GetRetryIntegrityTag([]byte("foobar"), connID2, protocol.Version1) 27 Expect(*t1).ToNot(Equal(*t2)) 28 }) 29 30 DescribeTable("using the test vectors", 31 func(version protocol.Version, data []byte) { 32 v := binary.BigEndian.Uint32(data[1:5]) 33 Expect(protocol.Version(v)).To(Equal(version)) 34 connID := protocol.ParseConnectionID(splitHexString("0x8394c8f03e515708")) 35 Expect(GetRetryIntegrityTag(data[:len(data)-16], connID, version)[:]).To(Equal(data[len(data)-16:])) 36 }, 37 Entry("v1", 38 protocol.Version1, 39 splitHexString("ff000000010008f067a5502a4262b574 6f6b656e04a265ba2eff4d829058fb3f 0f2496ba"), 40 ), 41 Entry("v2", 42 protocol.Version2, 43 splitHexString("cf6b3343cf0008f067a5502a4262b574 6f6b656ec8646ce8bfe33952d9555436 65dcc7b6"), 44 ), 45 ) 46 })