-
Notifications
You must be signed in to change notification settings - Fork 51
/
claimsheader.go
69 lines (50 loc) · 1.71 KB
/
claimsheader.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
package claimsheader
// NewClaimsHeader returns claims header handler
func NewClaimsHeader(opts ...Option) *ClaimsHeader {
c := &ClaimsHeader{}
for _, opt := range opts {
opt(c)
}
return c
}
// ToBytes generates the 32-bit header in bytes
// 0 1 2 3 4
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | D |CT|E| R (reserved) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// D [0:5] - Datapath version
// CT [6,7] - Compressed tag type
// E [8] - Encryption enabled
// R [9:31] - Reserved
func (c *ClaimsHeader) ToBytes() HeaderBytes {
claimsHeaderData := make([]byte, maxHeaderLen)
claimsHeaderData[0] |= c.datapathVersion.toMask().toUint8()
claimsHeaderData[0] |= c.compressionType.toMask().toUint8()
claimsHeaderData[1] |= boolToUint8(c.encrypt)
return claimsHeaderData
}
// CompressionType is the compression type
func (c *ClaimsHeader) CompressionType() CompressionType {
return c.compressionType
}
// Encrypt is the encrypt in bool
func (c *ClaimsHeader) Encrypt() bool {
return c.encrypt
}
// DatapathVersion is the datapath version
func (c *ClaimsHeader) DatapathVersion() DatapathVersion {
return c.datapathVersion
}
// SetCompressionType sets the compression type
func (c *ClaimsHeader) SetCompressionType(ct CompressionType) {
c.compressionType = ct
}
// SetEncrypt sets the encrypt
func (c *ClaimsHeader) SetEncrypt(e bool) {
c.encrypt = e
}
// SetDatapathVersion sets the datapath version
func (c *ClaimsHeader) SetDatapathVersion(dv DatapathVersion) {
c.datapathVersion = dv
}