forked from quic-go/quic-go
add Substract method for EntropyAccumulator
This commit is contained in:
@@ -12,6 +12,11 @@ func (e *EntropyAccumulator) Add(packetNumber protocol.PacketNumber, entropyFlag
|
||||
}
|
||||
}
|
||||
|
||||
// Add the contribution of the entropy flag of a given packet number
|
||||
func (e *EntropyAccumulator) Substract(packetNumber protocol.PacketNumber, entropyFlag bool) {
|
||||
e.Add(packetNumber, entropyFlag)
|
||||
}
|
||||
|
||||
// Get the byte of entropy
|
||||
func (e *EntropyAccumulator) Get() byte {
|
||||
return byte(*e)
|
||||
|
||||
@@ -11,15 +11,31 @@ var _ = Describe("EntropyAccumulator", func() {
|
||||
Expect(e.Get()).To(BeZero())
|
||||
})
|
||||
|
||||
It("adds entropy", func() {
|
||||
var e EntropyAccumulator
|
||||
e.Add(9, true)
|
||||
Expect(e.Get()).To(Equal(byte(0x02)))
|
||||
Context("Add", func() {
|
||||
It("adds entropy", func() {
|
||||
var e EntropyAccumulator
|
||||
e.Add(9, true)
|
||||
Expect(e.Get()).To(Equal(byte(0x02)))
|
||||
})
|
||||
|
||||
It("doesn't add entropy for zero entropy flags", func() {
|
||||
var e EntropyAccumulator
|
||||
e.Add(9, false)
|
||||
Expect(e.Get()).To(BeZero())
|
||||
})
|
||||
})
|
||||
|
||||
It("doesn't add entropy for zero entropy flags", func() {
|
||||
var e EntropyAccumulator
|
||||
e.Add(9, false)
|
||||
Expect(e.Get()).To(BeZero())
|
||||
Context("Substract", func() {
|
||||
It("calculates the correct entropy", func() {
|
||||
var e1 EntropyAccumulator
|
||||
e1.Add(3, true)
|
||||
|
||||
var e2 EntropyAccumulator
|
||||
e2.Add(1, true)
|
||||
e2.Add(3, true)
|
||||
e2.Substract(1, true)
|
||||
|
||||
Expect(e1).To(Equal(e2))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user