move connection ID generation from the utils to the protocol package

This commit is contained in:
Marten Seemann
2018-03-16 07:36:27 +01:00
parent da7708e470
commit af8971d8c9
4 changed files with 9 additions and 11 deletions

View File

@@ -1,18 +0,0 @@
package utils
import (
"crypto/rand"
"encoding/binary"
"github.com/lucas-clemente/quic-go/internal/protocol"
)
// GenerateConnectionID generates a connection ID using cryptographic random
func GenerateConnectionID() (protocol.ConnectionID, error) {
b := make([]byte, 8)
_, err := rand.Read(b)
if err != nil {
return 0, err
}
return protocol.ConnectionID(binary.LittleEndian.Uint64(b)), nil
}

View File

@@ -1,17 +0,0 @@
package utils
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Connection ID generation", func() {
It("generates random connection IDs", func() {
c1, err := GenerateConnectionID()
Expect(err).ToNot(HaveOccurred())
Expect(c1).ToNot(BeZero())
c2, err := GenerateConnectionID()
Expect(err).ToNot(HaveOccurred())
Expect(c1).ToNot(Equal(c2))
})
})