mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
pkcs7: update parameter names and documentation
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
parent
3bd42f5a82
commit
dd1dfb9bab
1 changed files with 12 additions and 12 deletions
|
|
@ -8,23 +8,23 @@ package pkcs7
|
|||
|
||||
import "bytes"
|
||||
|
||||
// Pad implements PKCS#7 padding as defined in [RFC2315]. It pads the plaintext
|
||||
// to the given blockSize in the range [1, 255]. This is normally used in
|
||||
// AES-CBC encryption.
|
||||
// Pad implements PKCS#7 padding as defined in [RFC2315]. It pads the data to
|
||||
// the given blockSize in the range [1, 255]. This is normally used in AES-CBC
|
||||
// encryption.
|
||||
//
|
||||
// [RFC2315]: https://www.ietf.org/rfc/rfc2315.txt
|
||||
func Pad(plaintext []byte, blockSize int) []byte {
|
||||
padding := blockSize - len(plaintext)%blockSize
|
||||
return append(plaintext, bytes.Repeat([]byte{byte(padding)}, padding)...)
|
||||
func Pad(data []byte, blockSize int) []byte {
|
||||
padding := blockSize - len(data)%blockSize
|
||||
return append(data, bytes.Repeat([]byte{byte(padding)}, padding)...)
|
||||
}
|
||||
|
||||
// Unpad implements PKCS#7 unpadding as defined in [RFC2315]. It unpads the
|
||||
// plaintext by reading the padding amount from the last byte of the plaintext.
|
||||
// This is normally used in AES-CBC decryption.
|
||||
// data by reading the padding amount from the last byte of the data. This is
|
||||
// normally used in AES-CBC decryption.
|
||||
//
|
||||
// [RFC2315]: https://www.ietf.org/rfc/rfc2315.txt
|
||||
func Unpad(plaintext []byte) []byte {
|
||||
length := len(plaintext)
|
||||
unpadding := int(plaintext[length-1])
|
||||
return plaintext[:length-unpadding]
|
||||
func Unpad(data []byte) []byte {
|
||||
length := len(data)
|
||||
unpadding := int(data[length-1])
|
||||
return data[:length-unpadding]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue