Debian Codegraph @

padding/align.go

raw symbols SCIP
1 // package padding provides various padding algorithms
2 package padding
3
4 import (
5 "bytes"
6 )
7
8 // Align left pads given byte array with zeros till it have at least bitSize length.
9 func Align(data []byte, bitSize int) []byte {
10
11 actual:=len(data)
12 required:=bitSize >> 3
13
14 if (bitSize % 8) > 0 {
15 required++ //extra byte if needed
16 }
17
18 if (actual >= required) {
19 return data
20 }
21
22 return append(bytes.Repeat([]byte{0}, required-actual), data...)
23 }