This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
forked from ekr/minq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet_test.go
74 lines (57 loc) · 1.58 KB
/
packet_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package minq
import (
"encoding/hex"
"fmt"
"testing"
)
var kTestpacketHeader = packetHeader{
0,
0x0123456789abcdef,
0xdeadbeef,
0xff000001,
}
// Packet header tests.
func packetHeaderEDE(t *testing.T, p *packetHeader) {
var p2 packetHeader
res, err := encode(p)
assertNotError(t, err, "Could not encode")
fmt.Println("Result = ", hex.EncodeToString(res))
_, err = decode(&p2, res)
assertNotError(t, err, "Could not decode")
res2, err := encode(&p2)
assertNotError(t, err, "Could not re-encode")
fmt.Println("Result2 = ", hex.EncodeToString(res2))
assertByteEquals(t, res, res2)
}
func TestLongHeader(t *testing.T) {
p := kTestpacketHeader
p.setLongHeaderType(packetTypeClientInitial)
packetHeaderEDE(t, &p)
}
/*
* TODO([email protected]): Rewrite this code and merge it into
* connection.go
// Mock for connection state
type ConnectionStateMock struct {
aead aeadFNV
}
func (c *ConnectionStateMock) established() bool { return false }
func (c *ConnectionStateMock) zeroRttAllowed() bool { return false }
func (c *ConnectionStateMock) expandPacketNumber(pn uint64) uint64 {
return pn
}
func TestEDEPacket(t *testing.T) {
var c ConnectionStateMock
p := Packet{
kTestpacketHeader,
[]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'},
}
encoded, err := encodePacket(&c, &c.aead, &p)
assertNotError(t, err, "Could not encode packet")
p2, err := decodePacket(&c, &c.aead, encoded)
assertNotError(t, err, "Could not decode packet")
encoded2, err := encodePacket(&c, &c.aead, p2)
assertNotError(t, err, "Could not re-encode packet")
assertByteEquals(t, encoded, encoded2)
}
*/