forked from quic-go/quic-go
add a type for arbitrary length Connection IDs, and parsing function
RFC 8999 allows Connection IDs of up to 255 bytes. Current QUIC versions only use up to 20 bytes.
This commit is contained in:
@@ -7,6 +7,19 @@ import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// An ArbitraryLenConnectionID is a QUIC Connection ID able to represent Connection IDs according to RFC 8999.
|
||||
// Future QUIC versions might allow connection ID lengths up to 255 bytes, while QUIC v1
|
||||
// restricts the length to 20 bytes.
|
||||
type ArbitraryLenConnectionID []byte
|
||||
|
||||
func (c ArbitraryLenConnectionID) Len() int {
|
||||
return len(c)
|
||||
}
|
||||
|
||||
func (c ArbitraryLenConnectionID) Bytes() []byte {
|
||||
return c
|
||||
}
|
||||
|
||||
// A ConnectionID in QUIC
|
||||
type ConnectionID []byte
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package protocol
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"io"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -105,4 +106,18 @@ var _ = Describe("Connection ID generation", func() {
|
||||
var c ConnectionID
|
||||
Expect(c.String()).To(Equal("(empty)"))
|
||||
})
|
||||
|
||||
Context("arbitrary length connection IDs", func() {
|
||||
It("returns the bytes", func() {
|
||||
b := make([]byte, 30)
|
||||
rand.Read(b)
|
||||
c := ArbitraryLenConnectionID(b)
|
||||
Expect(c.Bytes()).To(Equal(b))
|
||||
})
|
||||
|
||||
It("returns the length", func() {
|
||||
c := ArbitraryLenConnectionID(make([]byte, 156))
|
||||
Expect(c.Len()).To(Equal(156))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user