github.com/emmansun/gmsm@v0.29.1/padding/schemes.go (about)

     1  // Package padding implements some padding schemes for padding octets at the trailing end.
     2  package padding
     3  
     4  // Padding interface represents a padding scheme
     5  type Padding interface {
     6  	BlockSize() int
     7  	Pad(src []byte) []byte
     8  	Unpad(src []byte) ([]byte, error)
     9  }
    10  
    11  func NewPKCS7Padding(blockSize uint) Padding {
    12  	if blockSize == 0 || blockSize > 255 {
    13  		panic("padding: invalid block size")
    14  	}
    15  	return pkcs7Padding(blockSize)
    16  }
    17  
    18  func NewANSIX923Padding(blockSize uint) Padding {
    19  	if blockSize == 0 || blockSize > 255 {
    20  		panic("padding: invalid block size")
    21  	}
    22  	return ansiX923Padding(blockSize)
    23  }
    24  
    25  func NewISO9797M2Padding(blockSize uint) Padding {
    26  	if blockSize == 0 || blockSize > 255 {
    27  		panic("padding: invalid block size")
    28  	}
    29  	return iso9797M2Padding(blockSize)
    30  }