store the encryption level in the unpacked packet

This commit is contained in:
Marten Seemann 2017-02-24 13:16:30 +07:00
parent a972c7a21e
commit f88cbd801b
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
3 changed files with 24 additions and 6 deletions

View file

@ -12,11 +12,13 @@ import (
. "github.com/onsi/gomega"
)
type mockAEAD struct{}
type mockAEAD struct {
encLevelOpen protocol.EncryptionLevel
}
func (m *mockAEAD) Open(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) ([]byte, protocol.EncryptionLevel, error) {
res, err := (&crypto.NullAEAD{}).Open(dst, src, packetNumber, associatedData)
return res, protocol.EncryptionUnspecified, err
return res, m.encLevelOpen, err
}
func (m *mockAEAD) Seal(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) []byte {
return (&crypto.NullAEAD{}).Seal(dst, src, packetNumber, associatedData)
@ -58,6 +60,17 @@ var _ = Describe("Packet unpacker", func() {
Expect(packet.frames).To(Equal([]frames.Frame{f}))
})
It("saves the encryption level", func() {
f := &frames.ConnectionCloseFrame{ReasonPhrase: "foo"}
err := f.Write(buf, 0)
Expect(err).ToNot(HaveOccurred())
setData(buf.Bytes())
unpacker.aead.(*mockAEAD).encLevelOpen = protocol.EncryptionSecure
packet, err := unpacker.Unpack(hdrBin, hdr, data)
Expect(err).ToNot(HaveOccurred())
Expect(packet.encryptionLevel).To(Equal(protocol.EncryptionSecure))
})
It("unpacks STREAM frames", func() {
f := &frames.StreamFrame{
StreamID: 1,