-
Notifications
You must be signed in to change notification settings - Fork 51
/
bytes.go
30 lines (23 loc) · 1.02 KB
/
bytes.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
package claimsheader
// HeaderBytes is the claimsheader in bytes
type HeaderBytes []byte
// ToClaimsHeader parses the bytes and returns the ClaimsHeader
func (h HeaderBytes) ToClaimsHeader() *ClaimsHeader {
if h == nil || len(h) != maxHeaderLen {
return NewClaimsHeader()
}
compressionTypeMask := compressionTypeMask(h.extractHeaderAttribute(h[0], compressionTypeBitMask.toUint8()))
datapathVersionMask := datapathVersionMask(h.extractHeaderAttribute(h[0], datapathVersionBitMask.toUint8()))
pingTypeMask := pingTypeMask(h.extractHeaderAttribute(h[1], pingTypeBitMask.toUint8()))
return &ClaimsHeader{
compressionType: compressionTypeMask.toType(),
encrypt: uint8ToBool(h.extractHeaderAttribute(h[1], encryptionEnabledBit)),
pingType: pingTypeMask.toType(),
datapathVersion: datapathVersionMask.toType(),
}
}
// extractHeaderAttribute returns the attribute from byte
// mask - mask specific to the attribute
func (h HeaderBytes) extractHeaderAttribute(attr byte, mask uint8) uint8 {
return attr & mask
}