Initial signer rewrite in Go
This commit is contained in:
commit
a89275a8e4
9 changed files with 557 additions and 0 deletions
28
datastructures/common.go
Normal file
28
datastructures/common.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package datastructures
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
type Action uint8
|
||||
|
||||
const ActionNul = Action(0)
|
||||
|
||||
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
|
||||
func decode24BitLength(bytes []byte) int {
|
||||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue