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