mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 04:07:35 +03:00
use a sentinel error when a sealer is not yet available
This commit is contained in:
parent
d00828b762
commit
3db60534cf
5 changed files with 11 additions and 11 deletions
|
@ -576,7 +576,7 @@ func (h *cryptoSetup) GetHandshakeSealer() (LongHeaderSealer, error) {
|
|||
if h.initialSealer == nil {
|
||||
return nil, ErrKeysDropped
|
||||
}
|
||||
return nil, errors.New("CryptoSetup: no sealer with encryption level Handshake")
|
||||
return nil, ErrKeysNotYetAvailable
|
||||
}
|
||||
return h.handshakeSealer, nil
|
||||
}
|
||||
|
@ -586,7 +586,7 @@ func (h *cryptoSetup) Get1RTTSealer() (ShortHeaderSealer, error) {
|
|||
defer h.mutex.Unlock()
|
||||
|
||||
if !h.has1RTTSealer {
|
||||
return nil, errors.New("CryptoSetup: no sealer with encryption level 1-RTT")
|
||||
return nil, ErrKeysNotYetAvailable
|
||||
}
|
||||
return h.aead, nil
|
||||
}
|
||||
|
@ -607,7 +607,7 @@ func (h *cryptoSetup) GetHandshakeOpener() (LongHeaderOpener, error) {
|
|||
|
||||
if h.handshakeOpener == nil {
|
||||
if h.initialOpener != nil {
|
||||
return nil, ErrOpenerNotYetAvailable
|
||||
return nil, ErrKeysNotYetAvailable
|
||||
}
|
||||
// if the initial opener is also not available, the keys were already dropped
|
||||
return nil, ErrKeysDropped
|
||||
|
@ -620,7 +620,7 @@ func (h *cryptoSetup) Get1RTTOpener() (ShortHeaderOpener, error) {
|
|||
defer h.mutex.Unlock()
|
||||
|
||||
if !h.has1RTTOpener {
|
||||
return nil, ErrOpenerNotYetAvailable
|
||||
return nil, ErrKeysNotYetAvailable
|
||||
}
|
||||
return h.aead, nil
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
// ErrOpenerNotYetAvailable is returned when an opener is requested for an encryption level,
|
||||
// ErrKeysNotYetAvailable is returned when an opener or a sealer is requested for an encryption level,
|
||||
// but the corresponding opener has not yet been initialized
|
||||
// This can happen when packets arrive out of order.
|
||||
ErrOpenerNotYetAvailable = errors.New("CryptoSetup: opener at this encryption level not yet available")
|
||||
ErrKeysNotYetAvailable = errors.New("CryptoSetup: keys at this encryption level not yet available")
|
||||
// ErrKeysDropped is returned when an opener or a sealer is requested for an encryption level,
|
||||
// but the corresponding keys have already been dropped.
|
||||
ErrKeysDropped = errors.New("CryptoSetup: keys were already dropped")
|
||||
|
|
|
@ -85,9 +85,9 @@ var _ = Describe("Packet Unpacker", func() {
|
|||
PacketNumberLen: 2,
|
||||
}
|
||||
hdr, hdrRaw := getHeader(extHdr)
|
||||
cs.EXPECT().Get1RTTOpener().Return(nil, handshake.ErrOpenerNotYetAvailable)
|
||||
cs.EXPECT().Get1RTTOpener().Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
_, err := unpacker.Unpack(hdr, time.Now(), append(hdrRaw, payload...))
|
||||
Expect(err).To(MatchError(handshake.ErrOpenerNotYetAvailable))
|
||||
Expect(err).To(MatchError(handshake.ErrKeysNotYetAvailable))
|
||||
})
|
||||
|
||||
It("returns the error when unpacking fails", func() {
|
||||
|
|
|
@ -677,7 +677,7 @@ func (s *session) handleSinglePacket(p *receivedPacket, hdr *wire.Header) bool /
|
|||
switch err {
|
||||
case handshake.ErrKeysDropped:
|
||||
s.logger.Debugf("Dropping packet because we already dropped the keys.")
|
||||
case handshake.ErrOpenerNotYetAvailable:
|
||||
case handshake.ErrKeysNotYetAvailable:
|
||||
// Sealer for this encryption level not yet available.
|
||||
// Try again later.
|
||||
wasQueued = true
|
||||
|
|
|
@ -749,7 +749,7 @@ var _ = Describe("Session", func() {
|
|||
PacketNumberLen: protocol.PacketNumberLen1,
|
||||
PacketNumber: 1,
|
||||
}
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, handshake.ErrOpenerNotYetAvailable)
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, handshake.ErrKeysNotYetAvailable)
|
||||
packet := getPacket(hdr, nil)
|
||||
Expect(sess.handlePacketImpl(packet)).To(BeFalse())
|
||||
Expect(sess.undecryptablePackets).To(Equal([]*receivedPacket{packet}))
|
||||
|
@ -832,7 +832,7 @@ var _ = Describe("Session", func() {
|
|||
hdrLen1, packet1 := getPacketWithLength(srcConnID, 456)
|
||||
hdrLen2, packet2 := getPacketWithLength(srcConnID, 123)
|
||||
gomock.InOrder(
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, handshake.ErrOpenerNotYetAvailable),
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, handshake.ErrKeysNotYetAvailable),
|
||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(_ *wire.Header, _ time.Time, data []byte) (*unpackedPacket, error) {
|
||||
Expect(data).To(HaveLen(hdrLen2 + 123 - 3))
|
||||
return &unpackedPacket{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue