use separate functions per encryption level to get openers

This commit is contained in:
Marten Seemann 2019-06-10 14:34:42 +08:00
parent 14a31d49a0
commit d4d3f09ee3
5 changed files with 77 additions and 35 deletions

View file

@ -38,19 +38,23 @@ func newPacketUnpacker(cs handshake.CryptoSetup, version protocol.VersionNumber)
func (u *packetUnpacker) Unpack(hdr *wire.Header, data []byte) (*unpackedPacket, error) {
r := bytes.NewReader(data)
var opener handshake.Opener
var encLevel protocol.EncryptionLevel
var err error
switch hdr.Type {
case protocol.PacketTypeInitial:
encLevel = protocol.EncryptionInitial
opener, err = u.cs.GetInitialOpener()
case protocol.PacketTypeHandshake:
encLevel = protocol.EncryptionHandshake
opener, err = u.cs.GetHandshakeOpener()
default:
if hdr.IsLongHeader {
return nil, fmt.Errorf("unknown packet type: %s", hdr.Type)
}
encLevel = protocol.Encryption1RTT
opener, err = u.cs.Get1RTTOpener()
}
opener, err := u.cs.GetOpener(encLevel)
if err != nil {
return nil, err
}