2018-10-31 11:17:51 +01:00
|
|
|
package datastructures
|
|
|
|
|
|
|
|
import "encoding/binary"
|
|
|
|
|
|
|
|
type Action uint8
|
|
|
|
|
2021-01-04 08:15:02 +01:00
|
|
|
const (
|
|
|
|
ActionNul = Action(0)
|
|
|
|
ActionSign = Action(1)
|
|
|
|
ActionRevoke = Action(2)
|
|
|
|
)
|
2018-10-31 11:17:51 +01:00
|
|
|
|
2020-04-17 19:39:01 +02:00
|
|
|
func (a Action) String() string {
|
|
|
|
switch a {
|
|
|
|
case ActionNul:
|
|
|
|
return "NUL"
|
2021-01-04 08:15:02 +01:00
|
|
|
case ActionSign:
|
|
|
|
return "SIGN"
|
|
|
|
case ActionRevoke:
|
|
|
|
return "REVOKE"
|
2020-04-17 19:39:01 +02:00
|
|
|
default:
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-31 11:17:51 +01:00
|
|
|
func encode24BitLength(data []byte) []byte {
|
|
|
|
lengthBytes := make([]byte, 4)
|
|
|
|
binary.BigEndian.PutUint32(lengthBytes, uint32(len(data)))
|
|
|
|
return lengthBytes[1:]
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate length from 24 bits of data in network byte order
|
2020-04-17 19:39:01 +02:00
|
|
|
func Decode24BitLength(bytes []byte) int {
|
2018-10-31 11:17:51 +01:00
|
|
|
return int(binary.BigEndian.Uint32([]byte{0x0, bytes[0], bytes[1], bytes[2]}))
|
|
|
|
}
|
|
|
|
|
|
|
|
func CalculateXorCheckSum(byteBlocks [][]byte) byte {
|
|
|
|
var result byte = 0x0
|
|
|
|
for _, byteBlock := range byteBlocks {
|
|
|
|
for _, b := range byteBlock {
|
|
|
|
result ^= b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|