pkcs7

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)

Functions

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)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL