forked from apexskier/cryptoPadding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpadding.go
More file actions
33 lines (31 loc) · 1004 Bytes
/
padding.go
File metadata and controls
33 lines (31 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Package cryptoPadding implements several standard byte padding schemes for
// use in block ciphers, such as standard AES.
//
// Byte padding appends bytes to data to make its total length a multiple of
// some block size.
//
// Example usage
// import (
// "github.com/apexskier/cryptoPadding"
// "io/ioutil"
// )
// func main() {
// var padding cryptoPadding.AnsiX923
// data, _ = ioutil.ReadFile("myfile")
// paddedData = padding.Pad(data, 8)
// unpaddedData = padding.Unpad(paddedData, 8)
// }
package cryptoPadding
// BlockPadding represents an arbitrary byte padding scheme.
type BlockPadding interface {
Pad(data []byte, blockSize int) (output []byte, err error)
Unpad(data []byte, blockSize int) (output []byte, err error)
}
// padSize return the number of bytes needed to properly pad a size of data.
func padSize(dataSize, blockSize int) (ps int) {
ps = blockSize - (dataSize % blockSize)
if ps == 0 {
ps = blockSize
}
return
}