set the Long Header packet type based on the state of the handshake

This commit is contained in:
Marten Seemann
2017-10-27 08:39:06 +07:00
parent a65929f6cf
commit 3f62ea8673
14 changed files with 205 additions and 22 deletions

View File

@@ -28,6 +28,7 @@ type mockCryptoSetup struct {
divNonce []byte
encLevelSeal protocol.EncryptionLevel
encLevelSealCrypto protocol.EncryptionLevel
nextPacketType protocol.PacketType
}
var _ handshake.CryptoSetup = &mockCryptoSetup{}
@@ -49,6 +50,7 @@ func (m *mockCryptoSetup) GetSealerWithEncryptionLevel(protocol.EncryptionLevel)
}
func (m *mockCryptoSetup) DiversificationNonce() []byte { return m.divNonce }
func (m *mockCryptoSetup) SetDiversificationNonce(divNonce []byte) { m.divNonce = divNonce }
func (m *mockCryptoSetup) GetNextPacketType() protocol.PacketType { return m.nextPacketType }
var _ = Describe("Packet packer", func() {
var (
@@ -189,6 +191,13 @@ var _ = Describe("Packet packer", func() {
Expect(h.Version).To(Equal(versionIETFHeader))
})
It("sets the packet type based on the state of the handshake", func() {
packer.cryptoSetup.(*mockCryptoSetup).nextPacketType = 5
h := packer.getHeader(protocol.EncryptionSecure)
Expect(h.IsLongHeader).To(BeTrue())
Expect(h.Type).To(Equal(protocol.PacketType(5)))
})
It("uses the Short Header format for forward-secure packets", func() {
h := packer.getHeader(protocol.EncryptionForwardSecure)
Expect(h.IsLongHeader).To(BeFalse())