mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
rename the KeyPhase to KeyPhaseBit
This commit is contained in:
parent
7ba70cc8c2
commit
5a9c593463
10 changed files with 50 additions and 43 deletions
|
@ -34,7 +34,7 @@ type LongHeaderOpener interface {
|
||||||
// ShortHeaderOpener opens a short header packet
|
// ShortHeaderOpener opens a short header packet
|
||||||
type ShortHeaderOpener interface {
|
type ShortHeaderOpener interface {
|
||||||
headerDecryptor
|
headerDecryptor
|
||||||
Open(dst, src []byte, pn protocol.PacketNumber, kp protocol.KeyPhase, associatedData []byte) ([]byte, error)
|
Open(dst, src []byte, pn protocol.PacketNumber, kp protocol.KeyPhaseBit, associatedData []byte) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LongHeaderSealer seals a long header packet
|
// LongHeaderSealer seals a long header packet
|
||||||
|
@ -47,7 +47,7 @@ type LongHeaderSealer interface {
|
||||||
// ShortHeaderSealer seals a short header packet
|
// ShortHeaderSealer seals a short header packet
|
||||||
type ShortHeaderSealer interface {
|
type ShortHeaderSealer interface {
|
||||||
LongHeaderSealer
|
LongHeaderSealer
|
||||||
KeyPhase() protocol.KeyPhase
|
KeyPhase() protocol.KeyPhaseBit
|
||||||
}
|
}
|
||||||
|
|
||||||
// A tlsExtensionHandler sends and received the QUIC TLS extension.
|
// A tlsExtensionHandler sends and received the QUIC TLS extension.
|
||||||
|
|
|
@ -43,7 +43,7 @@ func setKeyUpdateInterval() {
|
||||||
type updatableAEAD struct {
|
type updatableAEAD struct {
|
||||||
suite cipherSuite
|
suite cipherSuite
|
||||||
|
|
||||||
keyPhase protocol.KeyPhase
|
keyPhase protocol.KeyPhaseBit
|
||||||
largestAcked protocol.PacketNumber
|
largestAcked protocol.PacketNumber
|
||||||
keyUpdateInterval uint64
|
keyUpdateInterval uint64
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ func (a *updatableAEAD) SetWriteKey(suite cipherSuite, trafficSecret []byte) {
|
||||||
a.nextSendAEAD = createAEAD(suite, a.nextSendTrafficSecret)
|
a.nextSendAEAD = createAEAD(suite, a.nextSendTrafficSecret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *updatableAEAD) Open(dst, src []byte, pn protocol.PacketNumber, kp protocol.KeyPhase, ad []byte) ([]byte, error) {
|
func (a *updatableAEAD) Open(dst, src []byte, pn protocol.PacketNumber, kp protocol.KeyPhaseBit, ad []byte) ([]byte, error) {
|
||||||
binary.BigEndian.PutUint64(a.nonceBuf[len(a.nonceBuf)-8:], uint64(pn))
|
binary.BigEndian.PutUint64(a.nonceBuf[len(a.nonceBuf)-8:], uint64(pn))
|
||||||
if kp != a.keyPhase {
|
if kp != a.keyPhase {
|
||||||
if a.firstRcvdWithCurrentKey == protocol.InvalidPacketNumber || pn < a.firstRcvdWithCurrentKey {
|
if a.firstRcvdWithCurrentKey == protocol.InvalidPacketNumber || pn < a.firstRcvdWithCurrentKey {
|
||||||
|
@ -215,7 +215,7 @@ func (a *updatableAEAD) shouldInitiateKeyUpdate() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *updatableAEAD) KeyPhase() protocol.KeyPhase {
|
func (a *updatableAEAD) KeyPhase() protocol.KeyPhaseBit {
|
||||||
if a.shouldInitiateKeyUpdate() {
|
if a.shouldInitiateKeyUpdate() {
|
||||||
a.rollKeys()
|
a.rollKeys()
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (mr *MockShortHeaderOpenerMockRecorder) DecryptHeader(arg0, arg1, arg2 inte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open mocks base method
|
// Open mocks base method
|
||||||
func (m *MockShortHeaderOpener) Open(arg0, arg1 []byte, arg2 protocol.PacketNumber, arg3 protocol.KeyPhase, arg4 []byte) ([]byte, error) {
|
func (m *MockShortHeaderOpener) Open(arg0, arg1 []byte, arg2 protocol.PacketNumber, arg3 protocol.KeyPhaseBit, arg4 []byte) ([]byte, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "Open", arg0, arg1, arg2, arg3, arg4)
|
ret := m.ctrl.Call(m, "Open", arg0, arg1, arg2, arg3, arg4)
|
||||||
ret0, _ := ret[0].([]byte)
|
ret0, _ := ret[0].([]byte)
|
||||||
|
|
|
@ -47,10 +47,10 @@ func (mr *MockShortHeaderSealerMockRecorder) EncryptHeader(arg0, arg1, arg2 inte
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyPhase mocks base method
|
// KeyPhase mocks base method
|
||||||
func (m *MockShortHeaderSealer) KeyPhase() protocol.KeyPhase {
|
func (m *MockShortHeaderSealer) KeyPhase() protocol.KeyPhaseBit {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "KeyPhase")
|
ret := m.ctrl.Call(m, "KeyPhase")
|
||||||
ret0, _ := ret[0].(protocol.KeyPhase)
|
ret0, _ := ret[0].(protocol.KeyPhaseBit)
|
||||||
return ret0
|
return ret0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
internal/protocol/key_phase.go
Normal file
22
internal/protocol/key_phase.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package protocol
|
||||||
|
|
||||||
|
// KeyPhaseBit is the key phase bit
|
||||||
|
type KeyPhaseBit bool
|
||||||
|
|
||||||
|
const (
|
||||||
|
// KeyPhaseZero is key phase 0
|
||||||
|
KeyPhaseZero KeyPhaseBit = false
|
||||||
|
// KeyPhaseOne is key phase 1
|
||||||
|
KeyPhaseOne KeyPhaseBit = true
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p KeyPhaseBit) String() string {
|
||||||
|
if p == KeyPhaseZero {
|
||||||
|
return "0"
|
||||||
|
}
|
||||||
|
return "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p KeyPhaseBit) Next() KeyPhaseBit {
|
||||||
|
return !p
|
||||||
|
}
|
18
internal/protocol/key_phase_test.go
Normal file
18
internal/protocol/key_phase_test.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package protocol
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Key Phases", func() {
|
||||||
|
It("has the correct string representation", func() {
|
||||||
|
Expect(KeyPhaseZero.String()).To(Equal("0"))
|
||||||
|
Expect(KeyPhaseOne.String()).To(Equal("1"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("returns the next key phase", func() {
|
||||||
|
Expect(KeyPhaseZero.Next()).To(Equal(KeyPhaseOne))
|
||||||
|
Expect(KeyPhaseOne.Next()).To(Equal(KeyPhaseZero))
|
||||||
|
})
|
||||||
|
})
|
|
@ -34,27 +34,6 @@ func (t PacketType) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyPhase is the key phase
|
|
||||||
type KeyPhase bool
|
|
||||||
|
|
||||||
const (
|
|
||||||
// KeyPhaseZero is key phase 0
|
|
||||||
KeyPhaseZero KeyPhase = false
|
|
||||||
// KeyPhaseOne is key phase 1
|
|
||||||
KeyPhaseOne KeyPhase = true
|
|
||||||
)
|
|
||||||
|
|
||||||
func (p KeyPhase) String() string {
|
|
||||||
if p == KeyPhaseZero {
|
|
||||||
return "0"
|
|
||||||
}
|
|
||||||
return "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p KeyPhase) Next() KeyPhase {
|
|
||||||
return !p
|
|
||||||
}
|
|
||||||
|
|
||||||
// A ByteCount in QUIC
|
// A ByteCount in QUIC
|
||||||
type ByteCount uint64
|
type ByteCount uint64
|
||||||
|
|
||||||
|
|
|
@ -15,16 +15,4 @@ var _ = Describe("Protocol", func() {
|
||||||
Expect(PacketType(10).String()).To(Equal("unknown packet type: 10"))
|
Expect(PacketType(10).String()).To(Equal("unknown packet type: 10"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("Key Phases", func() {
|
|
||||||
It("has the correct string representation", func() {
|
|
||||||
Expect(KeyPhaseZero.String()).To(Equal("0"))
|
|
||||||
Expect(KeyPhaseOne.String()).To(Equal("1"))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("returns the next key phase", func() {
|
|
||||||
Expect(KeyPhaseZero.Next()).To(Equal(KeyPhaseOne))
|
|
||||||
Expect(KeyPhaseOne.Next()).To(Equal(KeyPhaseZero))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -25,7 +25,7 @@ type ExtendedHeader struct {
|
||||||
PacketNumberLen protocol.PacketNumberLen
|
PacketNumberLen protocol.PacketNumberLen
|
||||||
PacketNumber protocol.PacketNumber
|
PacketNumber protocol.PacketNumber
|
||||||
|
|
||||||
KeyPhase protocol.KeyPhase
|
KeyPhase protocol.KeyPhaseBit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ExtendedHeader) parse(b *bytes.Reader, v protocol.VersionNumber) (*ExtendedHeader, error) {
|
func (h *ExtendedHeader) parse(b *bytes.Reader, v protocol.VersionNumber) (*ExtendedHeader, error) {
|
||||||
|
|
|
@ -432,7 +432,7 @@ func (p *packetPacker) composeNextPacket(maxFrameSize protocol.ByteCount) (paylo
|
||||||
return payload, nil
|
return payload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *packetPacker) getShortHeader(kp protocol.KeyPhase) *wire.ExtendedHeader {
|
func (p *packetPacker) getShortHeader(kp protocol.KeyPhaseBit) *wire.ExtendedHeader {
|
||||||
pn, pnLen := p.pnManager.PeekPacketNumber(protocol.Encryption1RTT)
|
pn, pnLen := p.pnManager.PeekPacketNumber(protocol.Encryption1RTT)
|
||||||
hdr := &wire.ExtendedHeader{}
|
hdr := &wire.ExtendedHeader{}
|
||||||
hdr.PacketNumber = pn
|
hdr.PacketNumber = pn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue