forked from quic-go/quic-go
select the right null AEAD algorithm depending on the version
This commit is contained in:
14
crypto/null_aead.go
Normal file
14
crypto/null_aead.go
Normal 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,
|
||||
}
|
||||
}
|
||||
@@ -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
17
crypto/null_aead_test.go
Normal 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{}))
|
||||
})
|
||||
})
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user