github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/controller/pkg/claimsheader/claimsheader.go (about)

     1  package claimsheader
     2  
     3  // NewClaimsHeader returns claims header handler
     4  func NewClaimsHeader(opts ...Option) *ClaimsHeader {
     5  
     6  	c := &ClaimsHeader{}
     7  
     8  	for _, opt := range opts {
     9  		opt(c)
    10  	}
    11  
    12  	return c
    13  }
    14  
    15  // ToBytes generates the 32-bit header in bytes
    16  //    0             1              2               3               4
    17  //  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
    18  //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    19  //  |     D     |CT |E|P|            R (reserved)                   |
    20  //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    21  //  D  [0:5]   - Datapath version
    22  //  CT [6,7]   - Compressed tag type
    23  //  E  [8]     - Encryption enabled
    24  //  P  [9]     - Ping enabled
    25  //  R  [10:31] - Reserved
    26  func (c *ClaimsHeader) ToBytes() HeaderBytes {
    27  
    28  	claimsHeaderData := make([]byte, maxHeaderLen)
    29  	claimsHeaderData[0] |= c.datapathVersion.toMask().toUint8()
    30  	claimsHeaderData[0] |= c.compressionType.toMask().toUint8()
    31  	claimsHeaderData[1] |= boolToUint8(encrypt, c.encrypt)
    32  	claimsHeaderData[1] |= boolToUint8(ping, c.ping)
    33  
    34  	return claimsHeaderData
    35  }
    36  
    37  // CompressionType is the compression type
    38  func (c *ClaimsHeader) CompressionType() CompressionType {
    39  
    40  	return c.compressionType
    41  }
    42  
    43  // Encrypt is the encrypt in bool
    44  func (c *ClaimsHeader) Encrypt() bool {
    45  
    46  	return c.encrypt
    47  }
    48  
    49  // DatapathVersion is the datapath version
    50  func (c *ClaimsHeader) DatapathVersion() DatapathVersion {
    51  
    52  	return c.datapathVersion
    53  }
    54  
    55  // Ping returns the ping in bool
    56  func (c *ClaimsHeader) Ping() bool {
    57  
    58  	return c.ping
    59  }
    60  
    61  // SetCompressionType sets the compression type
    62  func (c *ClaimsHeader) SetCompressionType(ct CompressionType) {
    63  
    64  	c.compressionType = ct
    65  }
    66  
    67  // SetEncrypt sets the encrypt
    68  func (c *ClaimsHeader) SetEncrypt(e bool) {
    69  
    70  	c.encrypt = e
    71  }
    72  
    73  // SetDatapathVersion sets the datapath version
    74  func (c *ClaimsHeader) SetDatapathVersion(dv DatapathVersion) {
    75  
    76  	c.datapathVersion = dv
    77  }
    78  
    79  // SetPing sets the ping
    80  func (c *ClaimsHeader) SetPing(ping bool) {
    81  
    82  	c.ping = ping
    83  }