replace version number literals with constants to make grepping easier

This commit is contained in:
Lucas Clemente 2016-06-03 11:09:48 +02:00
parent 556bf2fe4b
commit 240946dfde
13 changed files with 75 additions and 67 deletions

View file

@ -44,7 +44,7 @@ func DeriveKeysChacha20(version protocol.VersionNumber, forwardSecure bool, shar
return nil, err
}
if !forwardSecure && version >= protocol.VersionNumber(33) {
if !forwardSecure && version >= protocol.Version33 {
if err := diversify(myKey, myIV, divNonce); err != nil {
return nil, err
}

View file

@ -10,7 +10,7 @@ import (
var _ = Describe("KeyDerivation", func() {
It("derives non-fs keys", func() {
aead, err := DeriveKeysChacha20(
32,
protocol.Version32,
false,
[]byte("0123456789012345678901"),
[]byte("nonce"),
@ -29,7 +29,7 @@ var _ = Describe("KeyDerivation", func() {
It("derives fs keys", func() {
aead, err := DeriveKeysChacha20(
32,
protocol.Version32,
true,
[]byte("0123456789012345678901"),
[]byte("nonce"),
@ -48,7 +48,7 @@ var _ = Describe("KeyDerivation", func() {
It("does not use diversification nonces in FS key derivation", func() {
aead, err := DeriveKeysChacha20(
33,
protocol.Version33,
true,
[]byte("0123456789012345678901"),
[]byte("nonce"),
@ -67,7 +67,7 @@ var _ = Describe("KeyDerivation", func() {
It("uses diversification nonces in initial key derivation", func() {
aead, err := DeriveKeysChacha20(
33,
protocol.Version33,
false,
[]byte("0123456789012345678901"),
[]byte("nonce"),

View file

@ -106,7 +106,7 @@ func (f *AckFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error
}
// TODO: Remove once we drop support for <32
if version < protocol.VersionNumber(32) {
if version < protocol.Version32 {
b.WriteByte(0)
}
}
@ -265,7 +265,7 @@ func ParseAckFrame(r *bytes.Reader, version protocol.VersionNumber) (*AckFrame,
}
// TODO: Remove once we drop support for versions <32
if version < protocol.VersionNumber(32) {
if version < protocol.Version32 {
_, err = r.ReadByte()
if err != nil {
return nil, err

View file

@ -14,7 +14,7 @@ var _ = Describe("AckFrame", func() {
Context("when parsing", func() {
It("accepts sample frame", func() {
b := bytes.NewReader([]byte{0x40, 0xA4, 0x03, 0x23, 0x45, 0x01, 0x02, 0xFF, 0xEE, 0xDD, 0xCC})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.Entropy).To(Equal(byte(0xA4)))
Expect(frame.LargestObserved).To(Equal(protocol.PacketNumber(0x03)))
@ -25,7 +25,7 @@ var _ = Describe("AckFrame", func() {
It("parses a frame with a 48 bit packet number", func() {
b := bytes.NewReader([]byte{0x4C, 0xA4, 0x37, 0x13, 0xAD, 0xFB, 0xCA, 0xDE, 0x23, 0x45, 0x01, 0x02, 0xFF, 0xEE, 0xDD, 0xCC})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestObserved).To(Equal(protocol.PacketNumber(0xDECAFBAD1337)))
Expect(b.Len()).To(Equal(0))
@ -33,14 +33,14 @@ var _ = Describe("AckFrame", func() {
It("completely parses a frame with multiple timestamps", func() {
b := bytes.NewReader([]byte{0x40, 0xA4, 0x03, 0x23, 0x45, 0x03, 0x02, 0xFF, 0xEE, 0xDD, 0xCC, 0x12, 0x34, 0x56, 0x78, 0x90, 0xA0})
_, err := ParseAckFrame(b, 32)
_, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Len()).To(Equal(0))
})
It("parses a frame containing one NACK range", func() {
b := bytes.NewReader([]byte{0x60, 0x8, 0x3, 0x72, 0x1, 0x1, 0x0, 0xc0, 0x15, 0x0, 0x0, 0x1, 0x1, 0x1})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.HasNACK()).To(Equal(true))
Expect(frame.NackRanges).To(HaveLen(1))
@ -51,7 +51,7 @@ var _ = Describe("AckFrame", func() {
It("support version 31", func() {
b := bytes.NewReader([]byte{0x60, 0x8, 0x3, 0x72, 0x1, 0x1, 0x0, 0xc0, 0x15, 0x0, 0x0, 0x1, 0x1, 0x1, 0x0})
frame, err := ParseAckFrame(b, 31)
frame, err := ParseAckFrame(b, protocol.Version31)
Expect(err).ToNot(HaveOccurred())
Expect(frame.HasNACK()).To(Equal(true))
Expect(frame.NackRanges).To(HaveLen(1))
@ -63,7 +63,7 @@ var _ = Describe("AckFrame", func() {
It("parses a frame containing one NACK range with a 48 bit LargestObserved and missingPacketSequenceNumberDelta", func() {
var rangeLength uint64 = 3
b := bytes.NewReader([]byte{(0x4C | 0x20 | 0x03), 0x08, 0x37, 0x13, 0xAD, 0xFB, 0xCA, 0xDE, 0x72, 0x1, 0x1, 0x0, 0xc0, 0x15, 0x0, 0x0, 0x1, 0xFE, 0xCA, 0xEF, 0xBE, 0xAD, 0xDE, byte(rangeLength)})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestObserved).To(Equal(protocol.PacketNumber(0xDECAFBAD1337)))
Expect(frame.HasNACK()).To(Equal(true))
@ -75,7 +75,7 @@ var _ = Describe("AckFrame", func() {
It("parses a frame containing multiple NACK ranges", func() {
// sent packets 1, 3, 7, 15
b := bytes.NewReader([]byte{0x60, 0x2, 0xf, 0xb8, 0x1, 0x1, 0x0, 0xe5, 0x58, 0x4, 0x0, 0x3, 0x1, 0x6, 0x1, 0x2, 0x1, 0x0})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.HasNACK()).To(Equal(true))
Expect(frame.NackRanges).To(HaveLen(3))
@ -88,13 +88,13 @@ var _ = Describe("AckFrame", func() {
It("rejects a packet with an invalid NACK range", func() {
// LargestObserved: 8, NackRange: (8-7-3) to (8-7)
b := bytes.NewReader([]byte{0x60, 0x8, 0x7, 0x72, 0x1, 0x1, 0x0, 0xc0, 0x15, 0x0, 0x0, 0x1, 0x7, 0x3})
_, err := ParseAckFrame(b, 32)
_, err := ParseAckFrame(b, protocol.Version32)
Expect(err).To(MatchError(errInvalidNackRanges))
})
It("accepts truncated acks", func() {
b := bytes.NewReader([]byte{0x50, 0xA4, 0x03, 0x23, 0x45})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.Truncated).To(BeTrue())
Expect(b.Len()).To(BeZero())
@ -102,7 +102,7 @@ var _ = Describe("AckFrame", func() {
It("parses a frame with the largest observed missing", func() {
b := bytes.NewReader([]byte{0x60, 0x2, 0xf, 0xb8, 0x1, 0x1, 0x0, 0xe5, 0x58, 0x4, 0x0, 0x1, 0x0, 0x0})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.HasNACK()).To(Equal(true))
Expect(frame.NackRanges).To(HaveLen(1))
@ -113,7 +113,7 @@ var _ = Describe("AckFrame", func() {
Context("contiguous NACK ranges", func() {
It("parses a frame with a contiguous NACK range spanning two fields", func() {
b := bytes.NewReader([]byte{0x64, 0x8, 0x2E, 0x01, 0x72, 0x1, 0x1, 0x0, 0xc0, 0x15, 0x0, 0x0, 0x2, 0x1, 0x2b, 0x0, 0xff})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestObserved).To(Equal(protocol.PacketNumber(302)))
Expect(frame.NackRanges).To(HaveLen(1))
@ -122,7 +122,7 @@ var _ = Describe("AckFrame", func() {
It("parses a frame with a contiguous NACK range spanning more than two fields", func() {
b := bytes.NewReader([]byte{0x64, 0x8, 0x16, 0x05, 0x72, 0x1, 0x1, 0x0, 0xc0, 0x15, 0x0, 0x0, 0x6, 0x1, 0x13, 0x0, 0xff, 0x0, 0xff, 0x0, 0xff, 0x0, 0xff, 0x0, 0xff})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestObserved).To(Equal(protocol.PacketNumber(1302)))
Expect(frame.NackRanges).To(HaveLen(1))
@ -131,7 +131,7 @@ var _ = Describe("AckFrame", func() {
It("parses a frame with two contiguous NACK ranges", func() {
b := bytes.NewReader([]byte{0x64, 0x8, 0x23, 0x03, 0x72, 0x1, 0x1, 0x0, 0xc0, 0x15, 0x0, 0x0, 0x4, 0x1, 0x8f, 0x0, 0xff, 0x1, 0x8f, 0x0, 0xff})
frame, err := ParseAckFrame(b, 32)
frame, err := ParseAckFrame(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestObserved).To(Equal(protocol.PacketNumber(803)))
Expect(frame.NackRanges).To(HaveLen(2))
@ -142,7 +142,7 @@ var _ = Describe("AckFrame", func() {
It("rejects a frame with an invalid NACK range", func() {
// LargestObserved: 280, but NACK range is 301 packets long
b := bytes.NewReader([]byte{0x64, 0x8, 0x18, 0x01, 0x72, 0x1, 0x1, 0x0, 0xc0, 0x15, 0x0, 0x0, 0x2, 0x1, 0x2b, 0x0, 0xff})
_, err := ParseAckFrame(b, 32)
_, err := ParseAckFrame(b, protocol.Version32)
Expect(err).To(MatchError(errInvalidNackRanges))
})
})
@ -267,7 +267,7 @@ var _ = Describe("AckFrame", func() {
Entropy: 2,
LargestObserved: 1,
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
// check all values except the DelayTime
Expect(b.Bytes()[0:3]).To(Equal([]byte{0x40, 0x02, 0x01}))
@ -279,7 +279,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 5,
PacketReceivedTime: time.Now().Add(-750 * time.Millisecond),
}
frame.Write(b, 32)
frame.Write(b, protocol.Version32)
Expect(frame.DelayTime).To(BeNumerically("~", 750*time.Millisecond, 10*time.Millisecond))
delayTime := frame.DelayTime
var b2 bytes.Buffer
@ -293,7 +293,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 4,
NackRanges: []NackRange{{FirstPacketNumber: 2, LastPacketNumber: 2}},
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-8:]
Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges
@ -309,7 +309,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 4,
NackRanges: []NackRange{{FirstPacketNumber: 2, LastPacketNumber: 2}},
}
err := frame.Write(b, 31)
err := frame.Write(b, protocol.Version31)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-9:]
Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges
@ -328,7 +328,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 7,
NackRanges: []NackRange{nackRange1, nackRange2},
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges
@ -349,7 +349,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 258,
NackRanges: []NackRange{{FirstPacketNumber: 2, LastPacketNumber: 257}},
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(1))) // numRanges
@ -363,7 +363,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 302,
NackRanges: []NackRange{{FirstPacketNumber: 2, LastPacketNumber: 301}},
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges
@ -379,7 +379,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 259,
NackRanges: []NackRange{{FirstPacketNumber: 2, LastPacketNumber: 258}},
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+2*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(2))) // numRanges
@ -395,7 +395,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 603,
NackRanges: []NackRange{{FirstPacketNumber: 2, LastPacketNumber: 601}},
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+3*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(3))) // numRanges
@ -415,7 +415,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 655,
NackRanges: []NackRange{nackRange2, nackRange1},
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
missingPacketBytes := b.Bytes()[b.Len()-(1+4*7):]
Expect(missingPacketBytes[0]).To(Equal(uint8(4))) // numRanges
@ -434,7 +434,7 @@ var _ = Describe("AckFrame", func() {
frame := AckFrame{
LargestObserved: 7,
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()[0] & 0x4C).To(Equal(uint8(0x40)))
Expect(b.Bytes()[2]).To(Equal(uint8(7)))
@ -444,7 +444,7 @@ var _ = Describe("AckFrame", func() {
frame := AckFrame{
LargestObserved: 0x1337,
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()[0] & 0x4C).To(Equal(uint8(0x44)))
Expect(b.Bytes()[2:4]).To(Equal([]byte{0x37, 0x13}))
@ -454,7 +454,7 @@ var _ = Describe("AckFrame", func() {
frame := AckFrame{
LargestObserved: 0xDECAFBAD,
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()[0] & 0x4C).To(Equal(uint8(0x48)))
Expect(b.Bytes()[2:6]).To(Equal([]byte{0xAD, 0xFB, 0xCA, 0xDE}))
@ -464,7 +464,7 @@ var _ = Describe("AckFrame", func() {
frame := AckFrame{
LargestObserved: 0xDEADBEEFCAFE,
}
err := frame.Write(b, 32)
err := frame.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()[0] & 0x4C).To(Equal(uint8(0x4C)))
Expect(b.Bytes()[2:8]).To(Equal([]byte{0xFE, 0xCA, 0xEF, 0xBE, 0xAD, 0xDE}))
@ -497,7 +497,7 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 4,
NackRanges: []NackRange{{FirstPacketNumber: 2, LastPacketNumber: 2}},
}
err := f.Write(b, 31)
err := f.Write(b, protocol.Version31)
Expect(err).ToNot(HaveOccurred())
Expect(f.MinLength()).To(Equal(protocol.ByteCount(b.Len())))
})
@ -515,9 +515,9 @@ var _ = Describe("AckFrame", func() {
Entropy: 0xDE,
LargestObserved: 6789,
}
err := frameOrig.Write(b, 32)
err := frameOrig.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
frame, err := ParseAckFrame(bytes.NewReader(b.Bytes()), 32)
frame, err := ParseAckFrame(bytes.NewReader(b.Bytes()), protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.Entropy).To(Equal(frameOrig.Entropy))
Expect(frame.LargestObserved).To(Equal(frameOrig.LargestObserved))
@ -533,10 +533,10 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 15,
NackRanges: nackRanges,
}
err := frameOrig.Write(b, 32)
err := frameOrig.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := ParseAckFrame(r, 32)
frame, err := ParseAckFrame(r, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestObserved).To(Equal(frameOrig.LargestObserved))
Expect(frame.NackRanges).To(HaveLen(len(frameOrig.NackRanges)))
@ -553,10 +553,10 @@ var _ = Describe("AckFrame", func() {
LargestObserved: 1600,
NackRanges: nackRanges,
}
err := frameOrig.Write(b, 32)
err := frameOrig.Write(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := ParseAckFrame(r, 32)
frame, err := ParseAckFrame(r, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestObserved).To(Equal(frameOrig.LargestObserved))
Expect(frame.NackRanges).To(HaveLen(len(frameOrig.NackRanges)))

View file

@ -198,7 +198,7 @@ func (h *CryptoSetup) handleInchoateCHLO(sni string, data []byte, cryptoData map
}
var chloOrNil []byte
if h.version > protocol.VersionNumber(30) {
if h.version > protocol.Version30 {
chloOrNil = data
}
@ -307,7 +307,7 @@ func (h *CryptoSetup) handleCHLO(sni string, data []byte, cryptoData map[Tag][]b
// DiversificationNonce returns a diversification nonce if required in the next packet to be Seal'ed. See LockForSealing()!
func (h *CryptoSetup) DiversificationNonce() []byte {
if h.version < protocol.VersionNumber(33) {
if h.version < protocol.Version33 {
return nil
}
if h.receivedForwardSecurePacket || h.secureAEAD == nil {

View file

@ -171,7 +171,7 @@ var _ = Describe("Crypto setup", func() {
Context("diversification nonce", func() {
BeforeEach(func() {
cs.version = 33
cs.version = protocol.Version33
cs.secureAEAD = &mockAEAD{}
cs.receivedForwardSecurePacket = false
})
@ -181,7 +181,7 @@ var _ = Describe("Crypto setup", func() {
})
It("does not return nonce for version < 33", func() {
cs.version = 32
cs.version = protocol.Version32
Expect(cs.DiversificationNonce()).To(BeEmpty())
})
@ -207,7 +207,7 @@ var _ = Describe("Crypto setup", func() {
})
It("generates REJ messages for version 30", func() {
cs.version = protocol.VersionNumber(30)
cs.version = protocol.Version30
_, err := cs.handleInchoateCHLO("", sampleCHLO, nil)
Expect(err).ToNot(HaveOccurred())
Expect(signer.gotCHLO).To(BeFalse())

View file

@ -135,7 +135,7 @@ var _ = Describe("Packet packer", func() {
It("packs many control frames into 1 packets", func() {
f := &frames.AckFrame{LargestObserved: 1}
b := &bytes.Buffer{}
f.Write(b, 32)
f.Write(b, protocol.Version32)
maxFramesPerPacket := int(protocol.MaxFrameAndPublicHeaderSize-publicHeaderLen) / b.Len()
var controlFrames []frames.Frame
for i := 0; i < maxFramesPerPacket; i++ {

View file

@ -63,7 +63,7 @@ var _ = Describe("Packet unpacker", func() {
LargestObserved: 0x13,
Entropy: 0x37,
}
err := f.Write(buf, 32)
err := f.Write(buf, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
setReader(buf.Bytes())
packet, err := unpacker.Unpack(hdrBin, hdr, r)

View file

@ -9,9 +9,17 @@ import (
// VersionNumber is a version number as int
type VersionNumber int
// The version numbers, making grepping easier
const (
Version30 VersionNumber = 30 + iota
Version31
Version32
Version33
)
// SupportedVersions lists the versions that the server supports
var SupportedVersions = []VersionNumber{
30, 31, 32, 33,
Version30, Version31, Version32, Version33,
}
// SupportedVersionsAsTags is needed for the SHLO crypto message

View file

@ -10,12 +10,12 @@ import (
var _ = Describe("Version", func() {
It("converts tags to numbers", func() {
Expect(protocol.VersionTagToNumber('Q' + '1'<<8 + '2'<<16 + '3'<<24)).To(Equal(protocol.VersionNumber(123)))
Expect(protocol.VersionTagToNumber('Q' + '0'<<8 + '3'<<16 + '0'<<24)).To(Equal(protocol.VersionNumber(30)))
Expect(protocol.VersionTagToNumber('Q' + '0'<<8 + '3'<<16 + '0'<<24)).To(Equal(protocol.Version30))
})
It("converts number to tag", func() {
Expect(protocol.VersionNumberToTag(protocol.VersionNumber(123))).To(Equal(uint32('Q' + '1'<<8 + '2'<<16 + '3'<<24)))
Expect(protocol.VersionNumberToTag(protocol.VersionNumber(30))).To(Equal(uint32('Q' + '0'<<8 + '3'<<16 + '0'<<24)))
Expect(protocol.VersionNumberToTag(protocol.Version30)).To(Equal(uint32('Q' + '0'<<8 + '3'<<16 + '0'<<24)))
})
It("has proper tag list", func() {

View file

@ -45,7 +45,7 @@ func (h *publicHeader) WritePublicHeader(b *bytes.Buffer, version protocol.Versi
publicFlagByte |= 0x02
}
if !h.TruncateConnectionID {
if version < protocol.VersionNumber(33) {
if version < protocol.Version33 {
publicFlagByte |= 0x0c
} else {
publicFlagByte |= 0x08

View file

@ -17,7 +17,7 @@ var _ = Describe("Public Header", func() {
Expect(hdr.VersionFlag).To(BeTrue())
Expect(hdr.ResetFlag).To(BeFalse())
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x4cfa9f9b668619f6)))
Expect(hdr.VersionNumber).To(Equal(protocol.VersionNumber(30)))
Expect(hdr.VersionNumber).To(Equal(protocol.Version30))
Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(1)))
Expect(b.Len()).To(BeZero())
})
@ -84,7 +84,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 2,
PacketNumberLen: protocol.PacketNumberLen6,
}
hdr.WritePublicHeader(b, protocol.VersionNumber(32))
hdr.WritePublicHeader(b, protocol.Version32)
Expect(b.Bytes()).To(Equal([]byte{0x38 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 2, 0, 0, 0, 0, 0}))
})
@ -96,7 +96,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 2,
PacketNumberLen: protocol.PacketNumberLen6,
}
hdr.WritePublicHeader(b, protocol.VersionNumber(32))
hdr.WritePublicHeader(b, protocol.Version32)
// must be the first assertion
Expect(b.Len()).To(Equal(1 + 8)) // 1 FlagByte + 8 ConnectionID
firstByte, _ := b.ReadByte()
@ -111,7 +111,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 2,
PacketNumberLen: protocol.PacketNumberLen6,
}
hdr.WritePublicHeader(b, protocol.VersionNumber(32))
hdr.WritePublicHeader(b, protocol.Version32)
// must be the first assertion
Expect(b.Len()).To(Equal(1 + 8)) // 1 FlagByte + 8 ConnectionID
firstByte, _ := b.ReadByte()
@ -127,7 +127,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 2,
PacketNumberLen: protocol.PacketNumberLen6,
}
err := hdr.WritePublicHeader(b, protocol.VersionNumber(32))
err := hdr.WritePublicHeader(b, protocol.Version32)
Expect(err).To(MatchError(errResetAndVersionFlagSet))
})
@ -139,7 +139,7 @@ var _ = Describe("Public Header", func() {
PacketNumberLen: protocol.PacketNumberLen6,
PacketNumber: 1,
}
err := hdr.WritePublicHeader(b, protocol.VersionNumber(32))
err := hdr.WritePublicHeader(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x30, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0}))
})
@ -151,7 +151,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 1,
PacketNumberLen: protocol.PacketNumberLen1,
}
err := hdr.WritePublicHeader(b, protocol.VersionNumber(33))
err := hdr.WritePublicHeader(b, protocol.Version33)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x08, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0x01}))
})
@ -164,7 +164,7 @@ var _ = Describe("Public Header", func() {
PacketNumberLen: protocol.PacketNumberLen1,
DiversificationNonce: bytes.Repeat([]byte{1}, 32),
}
err := hdr.WritePublicHeader(b, protocol.VersionNumber(33))
err := hdr.WritePublicHeader(b, protocol.Version33)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{
0x0c, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c,
@ -247,7 +247,7 @@ var _ = Describe("Public Header", func() {
ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0xDECAFBAD,
}
err := hdr.WritePublicHeader(b, protocol.VersionNumber(32))
err := hdr.WritePublicHeader(b, protocol.Version32)
Expect(err).To(MatchError(errPacketNumberLenNotSet))
})
@ -258,7 +258,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 0xDECAFBAD,
PacketNumberLen: protocol.PacketNumberLen1,
}
err := hdr.WritePublicHeader(b, protocol.VersionNumber(32))
err := hdr.WritePublicHeader(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x08 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD}))
})
@ -270,7 +270,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 0xDECAFBAD,
PacketNumberLen: protocol.PacketNumberLen2,
}
err := hdr.WritePublicHeader(b, protocol.VersionNumber(32))
err := hdr.WritePublicHeader(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x18 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD, 0xFB}))
})
@ -282,7 +282,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 0x13DECAFBAD,
PacketNumberLen: protocol.PacketNumberLen4,
}
err := hdr.WritePublicHeader(b, protocol.VersionNumber(32))
err := hdr.WritePublicHeader(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x28 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD, 0xFB, 0xCA, 0xDE}))
})
@ -294,7 +294,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 0xBE1337DECAFBAD,
PacketNumberLen: protocol.PacketNumberLen6,
}
err := hdr.WritePublicHeader(b, protocol.VersionNumber(32))
err := hdr.WritePublicHeader(b, protocol.Version32)
Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x38 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD, 0xFB, 0xCA, 0xDE, 0x37, 0x13}))
})

View file

@ -187,7 +187,7 @@ func composeVersionNegotiation(connectionID protocol.ConnectionID) []byte {
VersionFlag: true,
}
// TODO: Update version number
err := responsePublicHeader.WritePublicHeader(fullReply, protocol.VersionNumber(32))
err := responsePublicHeader.WritePublicHeader(fullReply, protocol.Version32)
if err != nil {
utils.Errorf("error composing version negotiation packet: %s", err.Error())
}