tendermint/common/byteslice.go

35 lines
596 B
Go
Raw Normal View History

2014-10-30 03:32:09 -07:00
package common
2015-03-16 02:23:35 -07:00
func Fingerprint(slice []byte) []byte {
2014-10-30 03:32:09 -07:00
fingerprint := make([]byte, 6)
2015-03-16 02:23:35 -07:00
copy(fingerprint, slice)
2014-10-30 03:32:09 -07:00
return fingerprint
}
2015-03-16 02:23:35 -07:00
2015-03-20 05:47:52 -07:00
func IsZeros(slice []byte) bool {
for _, byt := range slice {
if byt != byte(0) {
return false
}
}
return true
}
2015-03-16 02:23:35 -07:00
func RightPadBytes(slice []byte, l int) []byte {
if l < len(slice) {
return slice
}
padded := make([]byte, l)
copy(padded[0:len(slice)], slice)
return padded
}
func LeftPadBytes(slice []byte, l int) []byte {
if l < len(slice) {
return slice
}
padded := make([]byte, l)
copy(padded[l-len(slice):], slice)
return padded
}