pkcs7
import "github.com/TheManticoreProject/Manticore/crypto/pkcs7"
Index
- Variables
- func Pad(buffer []byte, blockSize uint8) ([]byte, error)
- func Unpad(buffer []byte) ([]byte, error)
Variables
var (
ErrInvalidPadding = errors.New("invalid padding")
ErrUnPaddingEmptyBuffer = errors.New("cannot unpad an empty buffer")
ErrBlockSizeLessThanOne = errors.New("block size must be greater than 0")
ErrBlockSizeGreaterThan255 = errors.New("block size must be less than 255")
)
func Pad
func Pad(buffer []byte, blockSize uint8) ([]byte, error)
Pad appends padding to the input buffer to make its length a multiple of the block size.
Parameters: - buffer: A byte slice representing the input data to be padded. - blockSize: An unsigned 8-bit integer specifying the block size for padding.
Returns: - A byte slice containing the padded data. - An error if the block size is less than 1 or greater than 255.
The function performs the following steps: 1. Checks if the block size is valid (between 1 and 255). If not, it returns an error. 2. Calculates the padding length required to make the buffer length a multiple of the block size. 3. Appends the padding bytes to the buffer. Each padding byte has a value equal to the padding length.
Example usage: paddedData, err := Pad([]byte(“example”), 8)
if err != nil {
fmt.Printf("Error padding data: %s\n", err)
}
fmt.Printf(“Padded data: %x\n”, paddedData)
func Unpad
func Unpad(buffer []byte) ([]byte, error)