select the right null AEAD algorithm depending on the version

This commit is contained in:
Marten Seemann
2017-09-07 20:06:58 +03:00
parent 15e9e3658a
commit 23f3432b9d
4 changed files with 32 additions and 8 deletions

14
crypto/null_aead.go Normal file
View File

@@ -0,0 +1,14 @@
package crypto
import "github.com/lucas-clemente/quic-go/internal/protocol"
// NewNullAEAD creates a NullAEAD
func NewNullAEAD(p protocol.Perspective, v protocol.VersionNumber) AEAD {
if v == protocol.VersionTLS {
return &nullAEADFNV64a{}
}
return &nullAEADFNV128a{
perspective: p,
version: v,
}
}

View File

@@ -16,14 +16,6 @@ type nullAEADFNV128a struct {
var _ AEAD = &nullAEADFNV128a{}
// NewNullAEAD creates a NullAEAD
func NewNullAEAD(p protocol.Perspective, v protocol.VersionNumber) AEAD {
return &nullAEADFNV128a{
perspective: p,
version: v,
}
}
// Open and verify the ciphertext
func (n *nullAEADFNV128a) Open(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) ([]byte, error) {
if len(src) < 12 {

17
crypto/null_aead_test.go Normal file
View File

@@ -0,0 +1,17 @@
package crypto
import (
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("NullAEAD", func() {
It("selects the right FVN variant", func() {
Expect(NewNullAEAD(protocol.PerspectiveClient, protocol.Version39)).To(Equal(&nullAEADFNV128a{
perspective: protocol.PerspectiveClient,
version: protocol.Version39,
}))
Expect(NewNullAEAD(protocol.PerspectiveClient, protocol.VersionTLS)).To(Equal(&nullAEADFNV64a{}))
})
})

View File

@@ -10,6 +10,7 @@ const (
Version37
Version38
Version39
VersionTLS VersionNumber = 101
VersionWhatever VersionNumber = 0 // for when the version doesn't matter
VersionUnsupported VersionNumber = -1
VersionUnknown VersionNumber = -2