forked from quic-go/quic-go
introduce an absolute key phase, use it for key updates
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package protocol
|
||||
|
||||
// KeyPhase is the key phase
|
||||
type KeyPhase uint64
|
||||
|
||||
func (p KeyPhase) Bit() KeyPhaseBit {
|
||||
return p%2 == 1
|
||||
}
|
||||
|
||||
// KeyPhaseBit is the key phase bit
|
||||
type KeyPhaseBit bool
|
||||
|
||||
@@ -16,7 +23,3 @@ func (p KeyPhaseBit) String() string {
|
||||
}
|
||||
return "1"
|
||||
}
|
||||
|
||||
func (p KeyPhaseBit) Next() KeyPhaseBit {
|
||||
return !p
|
||||
}
|
||||
|
||||
@@ -11,8 +11,12 @@ var _ = Describe("Key Phases", func() {
|
||||
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))
|
||||
It("converts the key phase to the key phase bit", func() {
|
||||
Expect(KeyPhase(0).Bit()).To(Equal(KeyPhaseZero))
|
||||
Expect(KeyPhase(2).Bit()).To(Equal(KeyPhaseZero))
|
||||
Expect(KeyPhase(4).Bit()).To(Equal(KeyPhaseZero))
|
||||
Expect(KeyPhase(1).Bit()).To(Equal(KeyPhaseOne))
|
||||
Expect(KeyPhase(3).Bit()).To(Equal(KeyPhaseOne))
|
||||
Expect(KeyPhase(5).Bit()).To(Equal(KeyPhaseOne))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user